PHP strtolower() Function (original) (raw)

Skip to content

Summary: in this tutorial, you’ll learn how to use the PHP strtolower() function to make the lowercase version of a string.

Introduction to the PHP strtolower() function #

The strtolower() function accepts a string and returns a new string with all alphabetic characters converted to lowercase.

Here’s the syntax of the strtolower() function:

strtolower ( string $string ) : stringCode language: PHP (php)

The strtolower() uses the current locale to determine alphabetic characters.

To return a new string with a specific encoding with all alphabetic characters converted to lowercase, you use the mb_strtolower() function instead:

mb_strtolower ( string <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>t</mi><mi>r</mi><mi>i</mi><mi>n</mi><mi>g</mi><mo separator="true">,</mo><mi>s</mi><mi>t</mi><mi>r</mi><mi>i</mi><mi>n</mi><mi>g</mi><mi mathvariant="normal">∣</mi><mi>n</mi><mi>u</mi><mi>l</mi><mi>l</mi></mrow><annotation encoding="application/x-tex">string , string|null </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">in</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal">s</span><span class="mord mathnormal">t</span><span class="mord mathnormal" style="margin-right:0.02778em;">r</span><span class="mord mathnormal">in</span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mord">∣</span><span class="mord mathnormal">n</span><span class="mord mathnormal">u</span><span class="mord mathnormal" style="margin-right:0.01968em;">ll</span></span></span></span>encoding = null ) : stringCode language: PHP (php)

The following defines a lower() function that returns a new string with all characters converted lowercase:

`<?php

if (!function_exists('lower')) { function lower(string $value) : string { return mb_strtolower($value, 'UTF-8'); } }`Code language: PHP (php)

PHP strtolower() function examples #

The following example uses the strtolower() function to convert the string PHP to lowercase:

`<?php

echo strtolower('PHP');`Code language: PHP (php)

Output:

phpCode language: PHP (php)

Summary #

Did you find this tutorial useful?