在PHP中可以使用:strtoupper()函数、strtolower()函数、ucfirst()函数、lcfirst() 函数对字符串进行大小写处理。下面本篇文章就来给大家具体介绍一下,希望对大家有所帮助。
strtoupper()函数
strtoupper()函数可以将字符串作为参数,然后把字符串全部转换为大写,并返回。
基本语法:strtoupper(string)
示例:<?php
function toUpper($string){
return(strtoupper($string));
}
$string="Hello world!";
echo (toUpper($string));
?>
输出:
strtolower()函数
strtolower()函数可以将字符串作为参数,然后把字符串全部转换为小写,并返回。
基本语法:strtolower(string)
示例:<?php
function toUpper($string){
return(strtolower($string));
}
$string="JAVASCRIPT";
echo (toUpper($string));
?>
输出:
ucfirst()函数
ucfirst()函数可以将字符串作为参数,然后把字符串的首字母转换为大写,其他字符不变,并返回。
基本语法:ucfirst(string)
示例:<?php
function toUpper($string){
return(ucfirst($string));
}
$string="hello world!";
echo (toUpper($string));
?>
输出:
lcfirst() 函数
lcfirst()函数可以将字符串作为参数,然后把字符串的首字母转换为小写,其他字符不变,并返回。
基本语法:lcfirst(string)
示例:<?php
function toUpper($string){
return(lcfirst($string));
}
$string="PHP中文网!";
echo (toUpper($string));
?>
输出:
以上就是本篇文章的全部内容,希望能对大家的学习有所帮助。更多精彩内容大家可以关注php中文网相关教程栏目!!!