Home > Article > Daily Programming > PHP changes the case of letters or words
Use PHP to rewrite the uppercase and lowercase letters or words. We can do this through the functions strtoupper, strtolower, ucfirst, and ucwords in PHP.
# Below we will use a simple code example to introduce you to the method of changing the upper and lower case of letters or words in PHP.
The code example is as follows:
<?php //全部转换为大写字母 print(strtoupper("php chinese website")).'<br>'; //全部转换为小写字母 print(strtolower("PHP CHINESE WEBSITE")).'<br>'; //一句话开头大写 print(ucfirst("php chinese website")).'<br>'; //每个单词开头大写 print(ucwords("php chinese website")).'<br>';
The output result is as shown below:
Related functions:
strtoupper — Convert string to uppercase
strtoupper ( string $string ) : string
Convert all alphabetic characters in string to uppercase and return.
Note that "letter" is related to the current area. For example, in the default "C" locale, the character umlaut-a (ä) is not converted.
Parameter string, input string.
Return value, return the converted uppercase string.
strtolower - Set the string to lowercase
strtolower ( string $string ): string
Returns all alphabetic characters in string converted to lowercase.
Please note that 'alphabetic' is determined by the current locale. This means that for example in the default "C" locale, characters such as umlaut-A (Ä) are not converted.
Parameter string, input string.
Return value, return lowercase string.
ucfirst — Convert the first letter of the string to uppercase
ucfirst ( string $str ) : string
Convert the first character of str (if the first character is a letter) to uppercase and return this String.
Note that the definition of letters depends on the current locale. For example, in the default "C" locale, the character umlaut-a (ä) will not be converted.
Parameter str, input string.
Return value, return the result string.
ucwords —Convert the first letter of each word in the string to uppercase
ucwords ( string $str [, string $delimiters = " \t\r\n\f\v" ] ) : string
Convert the first character of each word in str (if the first character is a letter) Convert to uppercase letters and return this string.
The definition of the word here is the substring immediately following the delimiters parameter (default: space character, tab character, newline character, carriage return character, horizontal line and vertical bar).
Parameter str, input string.
delimiters Optional delimiters, including word splitting characters.
This article is an introduction to the method of changing the capitalization of letters or words in PHP. I hope it will be helpful to friends in need!
The above is the detailed content of PHP changes the case of letters or words. For more information, please follow other related articles on the PHP Chinese website!