PHP8.1.21版本已发布
vue8.1.21版本已发布
jquery8.1.21版本已发布

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

青灯夜游
青灯夜游 原创
2019-02-13 18:13:50 1836浏览

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

strtoupper()函数

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

基本语法:

strtoupper(string)

示例:

<?php 
function toUpper($string){ 
    return(strtoupper($string)); 
} 
$string="Hello world!";   
echo (toUpper($string)); 
?>

输出:

2.jpg

strtolower()函数

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

基本语法:

strtolower(string)

示例:

<?php 
function toUpper($string){ 
    return(strtolower($string)); 
} 
$string="JAVASCRIPT";   
echo (toUpper($string)); 
?>

输出:

3.jpg

ucfirst()函数

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

基本语法:

ucfirst(string)

示例:

<?php 
function toUpper($string){ 
    return(ucfirst($string)); 
} 
$string="hello world!";   
echo (toUpper($string)); 
?>

输出:

4.jpg

lcfirst() 函数

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

基本语法:

lcfirst(string)

示例:

<?php 
function toUpper($string){ 
    return(lcfirst($string)); 
} 
$string="PHP中文网!";   
echo (toUpper($string)); 
?>

输出:

5.jpg

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

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。