php字符串首字母转换大小写实例_PHP教程

WBOY
Freigeben: 2016-07-13 10:48:51
Original
1223 Leute haben es durchsucht

在php中如果我们要把字符转换成大小写直接使用strtolower或者strtoupper即可,但是要首字母要转换大小写我们需要使用ucwords相关函数

首字母变大写:ucwords()

 代码如下 复制代码

$foo = 'hello world!';
$foo = ucwords($foo); // Hello World!

$bar = 'HELLO WORLD!';
$bar = ucwords($bar); // HELLO WORLD!
$bar = ucwords(strtolower($bar)); // Hello World!
?>

第一个词首字母变大写:ucfirst()

 代码如下 复制代码

$foo = 'hello world!';
$foo = ucfirst($foo); // Hello world!

$bar = 'HELLO WORLD!';
$bar = ucfirst($bar); // HELLO WORLD!
$bar = ucfirst(strtolower($bar)); // Hello world!
?>

第一个词首字母小写lcfirst()

 代码如下 复制代码

$foo = 'HelloWorld';
$foo = lcfirst($foo); // helloWorld

$bar = 'HELLO WORLD!';

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/632754.htmlTechArticle在php中如果我们要把字符转换成大小写直接使用strtolower或者strtoupper即可,但是要首字母要转换大小写我们需要使用ucwords相关函数 首字母变...
Quelle:php.cn
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!