Letter case conversion functions in PHP include: strtolower, strtoupper, ucfirst, ucwords and other functions. This article will introduce to you how to use these letter case conversion functions.
1. Convert the string to lowercase
strtolower(): This function converts all characters of the incoming string parameter into lowercase and puts them back into the string in small definite form
The code is as follows |
Copy code |
代码如下 |
复制代码 |
echo strtolower("Hello WORLD!");
?>
|
echo strtolower("Hello WORLD!");
?>
|
2. Convert characters to uppercase
代码如下 |
复制代码 |
$str = "Mary Had A Little Lamb and She LOVED It So";
$str = strtoupper($str);
echo $str; // 打印 MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
?>
|
strtoupper(): The function of this function is opposite to the strtolower function. It converts all the characters of the incoming character parameter into uppercase and returns the string in uppercase. The usage is the same as strtolowe().
The code is as follows |
Copy code |
$str = "Mary Had A Little Lamb and She LOVED It So";
$str = strtoupper($str);
echo $str; // print MARY HAD A LITTLE LAMB AND SHE LOVED IT SO
代码如下 |
复制代码 |
$foo = 'hello world!';
$foo = ucwords($foo); // Hello World!
$bar = 'HELLO WORLD!';
$bar = ucwords($bar); // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>
|
?>
|
3. Convert the first character of the string to uppercase
ucfirst(): The function of this function is to change the first character of the string to uppercase. This function returns the string with the first character uppercase. The usage is the same as strtolowe().
The code is as follows |
Copy code |
代码如下 |
复制代码 |
$foo = 'hello world!';
$foo = ucfirst($foo); // Hello world!
$bar = 'HELLO WORLD!';
$bar = ucfirst($bar); // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?> |
$foo = 'hello world!';
$foo = ucwords($foo); // Hello World!
$bar = 'HELLO WORLD!';
$bar = ucwords($bar); // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>
|
4. Convert the first character of each word in the string to uppercase
ucwords(): This function changes the first character of each word in the passed string to uppercase. For example, "hello world", after being processed by this function, "Hello Word" will be returned. The usage is the same as strtolowe()
The code is as follows |
Copy code |
$foo = 'hello world!';
$foo = ucfirst($foo); // Hello world!
$bar = 'HELLO WORLD!';
$bar = ucfirst($bar); // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?> |
5.第一个词首字母小写lcfirst()
代码如下 |
复制代码 |
代码如下 |
复制代码 |
$foo = 'HelloWorld';
$foo = lcfirst($foo); // helloWorld
$bar = 'HELLO WORLD!';
$bar = lcfirst($bar); // hELLO WORLD!
$bar = lcfirst(strtoupper($bar)); // hELLO WORLD!
?>
|
$foo = 'HelloWorld';
$foo = lcfirst($foo); // helloWorld
$bar = 'HELLO WORLD!';
$bar = lcfirst($bar); // hELLO WORLD!
$bar = lcfirst(strtoupper($bar)); // hELLO WORLD!
?>
|
http://www.bkjia.com/PHPjc/445627.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/445627.htmlTechArticle在php中字母大小写转换函数包括有:strtolower,strtoupper,ucfirst,ucwords等等函数,本文章来分别给各位介绍这几个字母大小写转换函数使用方法。...