PHP |字符串函数

在本文中,我们了解了PHP中可用的一些基本字符串操作函数 PHP |字符串 .在本文中,我们将了解一些用于更改PHP中字符串大小写的字符串函数。以下是PHP中最常用的字符串大小写操作函数:

null

PHP中的strtoupper()函数

此函数将字符串作为参数,并返回所有字符均为大写的字符串。

语法 :

strtoupper($string)

用于说明strtoupper()函数用法的程序:

<?php
# PHP code to convert to Upper Case
function toUpper( $string ){
return ( strtoupper ( $string ));
}
// Driver Code
$string = "GeeksforGeeks" ;
echo (toUpper( $string ));
?>


输出:

GEEKSFORGEEKS

PHP中的strtolower()函数

此函数以字符串作为参数,ans返回所有小写字符的字符串。

语法 :

strtolower($string)

用于说明strtolower()函数用法的程序:

<?php
# PHP code to convert to Lower Case
function toLower( $string ){
return ( strtolower ( $string ));
}
// Driver Code
$string = "GeeksforGeeks" ;
echo (toLower( $string ));
?>


输出:

geeksforgeeks

PHP中的ucfirst()函数

此函数以字符串为参数,返回第一个字符为大写的字符串,并且所有其他大小写的字符保持不变。

语法 :

ucfirst($string)

用于说明ucfirst()函数用法的程序:

<?php
# PHP code to convert the first letter to Upper Case
function firstUpper( $string ){
return (ucfirst( $string ));
}
// Driver Code
$string = "welcome to GeeksforGeeks" ;
echo (firstUpper( $string ));
?>


输出:

Welcome to GeeksforGeeks

PHP中的lcfirst()函数

此函数以字符串为参数,返回第一个字符为小写的字符串,所有其他字符保持不变。

语法 :

lcfirst($string)

演示lcfirst()函数用法的程序:

<?php
# PHP code to convert the first letter to Lower Case
function firstLower( $string ){
return (lcfirst( $string ));
}
// Driver Code
$string = "WELCOME to GeeksforGeeks" ;
echo (firstLower( $string ));
?>


输出:

wELCOME to GeeksforGeeks

PHP中的ucwords()函数

此函数以字符串为参数,返回每个单词的第一个字符为大写的字符串,所有其他字符保持不变。

语法 :

ucwords($string)

用于说明ucwords()函数用法的程序:

<?php
# PHP code to convert the first letter
# of each word to Upper Case
function firstUpper( $string ){
return (ucwords( $string ));
}
// Driver Code
$string = "welcome to GeeksforGeeks" ;
echo (firstUpper( $string ));
?>


输出:

Welcome To GeeksforGeeks

PHP中的strlen()函数

此函数将字符串作为参数,并返回和表示字符串长度的整数值。它计算字符串的长度,包括所有空格和特殊字符。

语法 :

strlen($string)

演示strlen()函数用法的程序:

<?php
# PHP code to get the length of any string
function Length( $string ){
return ( strlen ( $string ));
}
// Driver Code
$string = "welcome to GeeksforGeeks" ;
echo (Length( $string ));
?>


输出:

24
© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享