每个单词的首字母转换为大写:ucwords()
<?php
$foo = 'hello world!';
$foo = ucwords($foo); // hello world!
$bar = 'hello world!';
$bar = ucwords($bar); // hello world!
$bar = ucwords(strtolower($bar)); // hello world!
?>
第一个单词首字母变大写:ucfirst()
<?php
$foo = 'hello world!';
$foo = ucfirst($foo); // hello world!
$bar = 'hello world!';
$bar = ucfirst($bar); // hello world!
$bar = ucfirst(strtolower($bar)); // hello world!
?>
第一个单词首字母变小写:lcfirst()
<?php
$foo = 'helloworld';
$foo = lcfirst($foo); // helloworld
$bar = 'hello world!';
$bar = lcfirst($bar); // hello world!
$bar = lcfirst(strtoupper($bar)); // hello world!
?>
所有 字母变大写:strtoupper()
所有 字母变小写:strtolower()
以上这篇php将字符串首字母大小写转换的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持硕编程。
【说明】:本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:254677821)!