Function to convert to lowercase: 1. strtolower(), syntax "strtolower($str)"; 2. mb_strtolower(), syntax "mb_strtolower($str,"coding")"; 3. lcfirst() , syntax "lcfirst($str)".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php transfer lowercase function
Function name | Function |
---|---|
strtolower | Convert the string to lowercase |
lcfirst | Convert the first letter of the string to lowercase |
mb_strtolower | Convert the string Convert to lowercase (difference from strtolower function) |
Let’s introduce them separately below.
1) strtolower
strtolower() function can convert the letters in the string to lowercase. The syntax format is as follows:
strtolower($str)
Among them, $string is a parameter of string type. This function can convert the letters in the parameter $string to lowercase and return the converted string.
The sample code is as follows:
<?php header("Content-type:text/html;charset=utf-8"); $str = "HTTPS://WWW.PHP.CN/"; echo "原字符串:".$str."<br>"; $str = strtolower($str); echo "转小写后:".$str; ?>
The running results are as follows:
##2) mb_strtolower## The function of #mb_strtolower() function is similar to that of strtolower() function. It can also convert the letters in the string to lowercase, and the mb_strtolower() function can also set the character encoding of the parameter. The syntax format is as follows:
mb_strtolower($str [, $encoding = mb_internal_encoding()])
Among them, $str is the string that needs to be converted, and $encoding is an optional parameter used to set the character encoding of the parameter.
The difference from the strtolower() function is that the detection of alphabetic characters in $str is based on the Unicode attribute of the character. The behavior of the function is therefore independent of the language setting and can convert any character with a "letter" attribute, such as the umlaut A (Ä).
The sample code is as follows:
<?php header("Content-type:text/html;charset=utf-8"); $str = "HTTPS://WWW.PHP.CN/"; $str = strtolower($str); echo $str.'<br>'; $str = "Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός"; $str = mb_strtolower($str, 'UTF-8'); echo $str; ?>
The running result is as follows:
##3) lcfirst
## The #lcfirst() function can convert the first character of a string to lowercase. The syntax format is as follows: lcfirst($str)
The sample code is as follows:
<?php $str = 'Hello World!'; $str = lcfirst($str); echo $str.'<br>'; $str2 = 'HELLO WORLD!'; $str2 = lcfirst($str2); echo $str2; ?>
The running results are as follows:
##Recommended learning: "
PHP Video Tutorial"
The above is the detailed content of What are the functions that convert php to lowercase?. For more information, please follow other related articles on the PHP Chinese website!