php實現(xiàn)字符串首字母轉(zhuǎn)換成大寫的方法

字號:


    這篇文章主要介紹了php實現(xiàn)字符串首字母轉(zhuǎn)換成大寫的方法,涉及php中ucfirst及ucwords函數(shù)的使用技巧,需要的朋友可以參考下
    本文實例講述了php實現(xiàn)字符串首字母轉(zhuǎn)換成大寫的方法。分享給大家供大家參考。具體分析如下:
    php中可以通過ucfirst函數(shù)將一個字符串中的第一個字母轉(zhuǎn)換成大寫,而ucwords函數(shù)可以將一個字符串中每個單詞的首字母轉(zhuǎn)換成大寫
    <?php
    $string = "php string functions are easy to use.";
    $sentence = ucfirst($string);
    $title = ucwords($string);
    print("$sentence\n");
    print("$title\n");
    print("\n");
    ?>
    輸出結(jié)果如下:
    Php string functions are easy to use.
    Php String Functions Are Easy To Use
    希望本文所述對大家的php程序設(shè)計有所幫助。