好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

PHP如何对字符串进行大小写处理

在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)); 
?>

输出:

以上就是本篇文章的全部内容,希望能对大家的学习有所帮助。更多精彩内容大家可以关注Gxl网相关教程栏目!!!

以上就是PHP如何对字符串进行大小写处理的详细内容,更多请关注Gxl网其它相关文章!

查看更多关于PHP如何对字符串进行大小写处理的详细内容...

  阅读:47次