PHP各种将字符串转换为大小写

远昔 代码记录 2023-12-11 246 0

分享一下PHP各种花式转换字符串为大小写(其实是想水一下文章)

将所有字母转换为大写

$str = "yuanxi_boke";
$str = strtoupper($str);
echo $str; //输出:YUANXI_BOKE

将所有字母转换为小写

$str = "YUANXI_BOKE";    //定义需要转换的字符串
$str = strtolower($str);
echo $str; //输出:yuanxi_boke

将字符串中每个单词的首字母转换为大写

$foo = '远昔博客yx yuanxi_boke yx
xiaobaiyun';
$foo = ucwords($foo);
echo $foo; //输出:远昔博客yx Yuanxi_boke Yx Xiaobaiyun

将首个字符转换为大写

$foo = 'yx yuanxi_boke';
$foo = ucfirst($foo);
echo $foo;//输出:Yx yuanxi_boke

将末尾字符转换为大写

$foo='yuanxiy';
$foo=ucfirst(strrev($foo)); //strrev反转顺序
$foo=strrev($foo); echo $foo; //输出:yuanxiY

评论

发表评论:

挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论