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

来源:青灯夜游 发布时间:2019-03-23 16:08:53 阅读量:772

在PHP中可以使用:strtoupper()函数、strtolower()函数、ucfirst()函数、lcfirst() 函数对字符串进行大小写处理。下面本篇文章就来给大家具体介绍一下,希望对大家有所帮助。

strtoupper()函数

strtoupper()函数可以将字符串作为参数,然后把字符串全部转换为大写,并返回。

基本语法:

1

strtoupper(string)

示例:

1

2

3

4

5

6

7

<?php

function toUpper($string){

    return(strtoupper($string));

}

$string="Hello world!";  

echo (toUpper($string));

?>

输出:

2.jpg

strtolower()函数

strtolower()函数可以将字符串作为参数,然后把字符串全部转换为小写,并返回。

基本语法:

1

strtolower(string)

示例:

1

2

3

4

5

6

7

<?php

function toUpper($string){

    return(strtolower($string));

}

$string="JAVASCRIPT";  

echo (toUpper($string));

?>

输出:

3.jpg

ucfirst()函数

ucfirst()函数可以将字符串作为参数,然后把字符串的首字母转换为大写,其他字符不变,并返回。

基本语法:

1

ucfirst(string)

示例:

1

2

3

4

5

6

7

<?php

function toUpper($string){

    return(ucfirst($string));

}

$string="hello world!";  

echo (toUpper($string));

?>

输出:

4.jpg

lcfirst() 函数

lcfirst()函数可以将字符串作为参数,然后把字符串的首字母转换为小写,其他字符不变,并返回。

基本语法:

1

lcfirst(string)

示例:

1

2

3

4

5

6

7

<?php

function toUpper($string){

    return(lcfirst($string));

}

$string="PHP中文网!";  

echo (toUpper($string));

?>

输出:

5.jpg


标签: PHP
分享:
评论:
你还没有登录,请先