PHP將字符串首字母大小寫轉(zhuǎn)換的實例
更新時間:2017年01月21日 08:54:42 投稿:jingxian
下面小編就為大家?guī)硪黄狿HP將字符串首字母大小寫轉(zhuǎn)換的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
每個單詞的首字母轉(zhuǎn)換為大寫: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將字符串首字母大小寫轉(zhuǎn)換的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
您可能感興趣的文章:
相關(guān)文章
laravel手動創(chuàng)建數(shù)組分頁的實現(xiàn)代碼
這篇文章主要介紹了laravel手動創(chuàng)建數(shù)組分頁的實現(xiàn)代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2018-06-06將PHP程序中返回的JSON格式數(shù)據(jù)用gzip壓縮輸出的方法
這篇文章主要介紹了將PHP中返回的JSON格式數(shù)據(jù)用gzip壓縮輸出的方法,文中示例環(huán)境為Linux系統(tǒng)與Apache服務(wù)器,需要的朋友可以參考下2016-03-03從零開始學YII2框架(二)通過 Composer 安裝擴展插件
在使用Yii框架開發(fā)的過程中,有一些優(yōu)秀的插件可以讓我們事半功倍。下面來介紹通過Composer安裝Yii2插件的方法。2014-08-08