PHP 大小写转换、首字母大写、每个单词首字母大写转换相关函数

strtolower()

该函数将传入的字符串参数所有的字符都转换成小写,并以小定形式放回这个字符串

$str = "Mary Had A Little Lamb and She LOVED It So"; 
$str = strtolower($str); 
echo $str; // Prints mary had a little lamb and she loved it so 

strtoupper()

该函数的作用同strtolower函数相反,是将传入的字符参数的字符全部转换成大写,并以大写的形式返回这个字符串.用法同strtolowe()一样。

$str = "Mary Had A Little Lamb and She LOVED It So"; 
$str = strtoupper($str); 
echo $str; // Prints MARY HAD A LITTLE LAMB AND SHE LOVED IT SO 

ucfirst()

该函数的作用是将字符串的第一个字符改成大写,该函数返回首字符大写的字符串.用法同strtolowe()一样。

$foo = 'hello world!'; 
$foo = ucfirst($foo);             // Hello world! 
     
$bar = 'HELLO WORLD!'; 
$bar = ucfirst($bar);             // HELLO WORLD! 
$bar = ucfirst(strtolower($bar)); // Hello world! 

ucwords()

该函数将传入的字符串的每个单词的首字符变成大写。如”imphper cn”,经过该函数处理后,将返回”Imphper Cn”。用法同strtolower()一样 。

$foo = 'hello world!'; 
$foo = ucwords($foo);             // Hello World!  
     
$bar = 'HELLO WORLD!'; 
$bar = ucwords($bar);             // HELLO WORLD! 
$bar = ucwords(strtolower($bar)); // Hello World! 

© 版权声明
THE END

喜欢就支持一下吧

点赞0 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容