您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php把字符串中的首字符转换为大写的函数ucfirst()

2024/6/30 18:00:51发布16次查看
实例
把 hello 的首字符转换为大写:
<?php echo ucfirst("hello world!"); ?>
定义和用法
ucfirst() 函数把字符串中的首字符转换为大写。
相关函数:
lcfirst() - 把字符串中的首字符转换为小写
ucwords() - 把字符串中每个单词的首字符转换为大写
strtoupper() - 把字符串转换为大写
strtolower() - 把字符串转换为小写
语法
ucfirst(string)
参数 描述
string 必需。规定要转换的字符串。
技术细节
返回值: 返回已转换的字符串。
php 版本: 4+
该函数演示了如何通过ucfirst 函数将字符串首字符转换成大写
<!doctype html public "-//w3c//dtd html 4.01 transitional//en" "http://www.w3.org/tr/html4/loose.dtd"> <html> <head> <title> ucfirst.php </title> <meta charset="utf-8"> <meta name="author" content=""> <meta name="keywords" content=""> <meta name="description" content=""> </head> <body> <?php //原来首字符小写 $foo = 'hello world!'; $foo2 = ucfirst($foo); //输出 hello world! echo $foo . "<br>"; echo $foo2 . "<br>"; //首字符大写,则不改变 $bar = 'hello world!'; $bar = ucfirst($bar); //输出 hello world! echo $bar . "<br>"; //将所有字符变成小写后,再将首字符编程大写 $bar = ucfirst(strtolower($bar)); //输出 hello world! echo $bar . "<br>"; ?> </body> </html> hello world! hello world! hello world! hello world!
以上就是php把字符串中的首字符转换为大写的函数ucfirst()的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product