这个 ucfirst() 函数是PHP中的一个内置函数,它以字符串作为参数,返回第一个大写字符的字符串,所有其他字符保持不变。
null
语法:
ucfirst($string)
参数: 该函数只接受一个参数 $string 这是强制性的。此参数表示其第一个字符将更改为大写的字符串。
返回值: 该函数仅通过将传递的参数的第一个字符更改为大写来返回相同的字符串 $string。
例如:
Input : "geeks for geeks" Output : Geeks for geeks Input : "Chetna Agarwal" Output : Chetna Agarwal
下面的程序演示了PHP中的ucfirst()函数:
项目1: 下面的程序演示了ucfirst()函数的用法。
<?php // PHP program that demonstrates the // use of ucfirst() function $str = "geeks for geeks" ; // converts the first case to upper case // and prints the string echo (ucfirst( $str )); ?> |
输出:
Geeks for geeks
项目2: 下面的程序演示了当起始字符为大写时ucfirst()函数的用法。
<?php // PHP program that demonstrates the // use of ucfirst() function when // the first case is already in uppercase $str = "Chetna Agarwal" ; // already the first character is in upper case // so prints the same string only echo (ucfirst( $str )); ?> |
输出:
Chetna Agarwal
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END