Home > Article > Backend Development > How to case strings in PHP
In PHP, you can use: strtoupper() function, strtolower() function, ucfirst() function, lcfirst() function to case strings. The following article will give you a detailed introduction, I hope it will be helpful to you.
strtoupper() function
strtoupper() function can take a string as a parameter, and then The string is converted to all uppercase and returned.
Basic syntax:
strtoupper(string)
Example:
<?php function toUpper($string){ return(strtoupper($string)); } $string="Hello world!"; echo (toUpper($string)); ?>
Output:
##strtolower( )Function
strtolower() function can take a string as a parameter, then convert all strings to lowercase and return. Basic syntax:strtolower(string)Example:
<?php function toUpper($string){ return(strtolower($string)); } $string="JAVASCRIPT"; echo (toUpper($string)); ?>Output:
##ucfirst( )Function ucfirst() function can take a string as a parameter, and then convert the first letter of the string to uppercase, leaving other characters unchanged, and return.
Basic syntax:
ucfirst(string)
Example:
<?php function toUpper($string){ return(ucfirst($string)); } $string="hello world!"; echo (toUpper($string)); ?>
Output:
##lcfirst( ) Functionlcfirst() function can take a string as a parameter, and then convert the first letter of the string to lowercase, leaving the other characters unchanged, and return it.
Basic syntax:lcfirst(string)Example:
<?php function toUpper($string){ return(lcfirst($string)); } $string="PHP中文网!"; echo (toUpper($string)); ?>Output:
The above is the entire content of this article , I hope it can be helpful to everyone’s study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !
The above is the detailed content of How to case strings in PHP. For more information, please follow other related articles on the PHP Chinese website!