Home>Article>Backend Development> How to convert lowercase to uppercase in php string
How to convert php string from lowercase to uppercase: 1. Use strtoupper() function, syntax "strtoupper($string)"; 2. Use mb_strtoupper() function, syntax "mb_strtoupper($string,$encoding) )".
The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer
php string will Convert lowercase to uppercase
Method 1: Use strtoupper() function
strtoupper() function can convert letters in a string to uppercase , the syntax format is as follows:
strtoupper($string)
Among them, $string is a parameter of string type. This function can convert the letters in the parameter $string to uppercase and return the converted string.
The sample code is as follows:
The running results are as follows:
HTTPS://WWW.PHP.CN/
Method 2: Use the mb_strtoupper() function
mb_strtoupper( ) The function of the function is similar to the strtoupper() function. It can also convert letters in the string to uppercase, and the mb_strtoupper() function can also set the character encoding of the parameter. Its syntax is as follows:
mb_strtoupper($string [, $encoding = mb_internal_encoding()])
Among them, $string 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 strtoupper() function is that the letters in $string are determined through the Unicode character attribute. Therefore, the mb_strtoupper() function is not affected by the locale setting and can convert any character with a "letter" attribute, such as a umlaut (ä).
The sample code is as follows:
'; $str = "Τάχιστη αλώπηξ βαφής ψημένη γη, δρασκελίζει υπέρ νωθρού κυνός"; $str = mb_strtoupper($str, 'UTF-8'); echo $str; ?>
The running results are as follows:
##Recommended learning:The above is the detailed content of How to convert lowercase to uppercase in php string. For more information, please follow other related articles on the PHP Chinese website!