PHP String strtolower()函數
strtolower()是PHP中最常用的函數之一,廣泛用于將字符串轉換為小寫。愛掏網 - it200.com它接受一個字符串作為參數,并將該字符串中的所有大寫英文字母轉換為小寫。愛掏網 - it200.com其他字符(如數字和特殊字符)保持不變。愛掏網 - it200.com PHP 4+ 版本支持該函數。愛掏網 - it200.com
注意:strtolower() 是一個二進制安全的函數。愛掏網 - it200.com
PHP中還有其他類似于strtolower()函數的函數:
- strtolower() - 將字符串轉換為大寫。愛掏網 - it200.com
- lcfirst() - 將字符串的第一個字符轉換為小寫。愛掏網 - it200.com
- ucfirst() - 將字符串的第一個字符轉換為大寫。愛掏網 - it200.com
- ucwords() - 將字符串中每個單詞的第一個字符轉換為大寫。愛掏網 - it200.com
語法
strtolower()函數的語法如下,它只接受一個字符串參數。愛掏網 - it200.com
strtoupper($string)
參數
$string(必填): 這是該函數的一個必填參數,用于指定要轉換為小寫的字符串。愛掏網 - it200.com簡單來說,它是一個被轉換為小寫的字符串。愛掏網 - it200.com
返回值
它返回轉換為小寫的字符串。愛掏網 - it200.com
示例
strtolower()是PHP的一個廣泛使用的函數。愛掏網 - it200.com下面給出了一些示例。愛掏網 - it200.com借助這些示例,我們可以實際了解該函數的工作原理。愛掏網 - it200.com
示例1
<?php
//original string
input_str = "All Is Well";
//string converted into lowercaseresult_str = strtolower(input_str);
echoresult_str;
?>
輸出:
all is well
示例2
<?php
//original string
input_str = "ALAYMA IS A CUTE AND SINCERE GIRL.";
echo "<b>String before conversion: </b>".input_str;
echo "</br>";
//string converted into lowercase
result_str = strtolower(input_str);
echo "<b>String after conversion: </b>". $result_str;
?>
輸出:
String before conversion: ALAYMA IS A CUTE AND SINCERE GIRL.
String after conversion: alayma is a cute and sincere girl.
示例3
在這個示例中,我們將看到在應用strtolower()函數后特殊字符保持不變。愛掏網 - it200.com它只轉換字母字符,而特殊符號沒有改變。愛掏網 - it200.com
<?php
input_str = "!, @, %,, And # Are The Special Symbols.";
echo "<b>String before conversion: </b>". input_str;
echo "</br>";
//string converted into lowercaseresult_str = strtolower(input_str);
echo "<b>String after conversion: </b>".result_str;
?>
輸出:
String before conversion: !, @, %, , And # Are The Special Symbols.
String after conversion: !, @, %,, and # are the special symbols.
聲明:所有內容來自互聯網搜索結果,不保證100%準確性,僅供參考。如若本站內容侵犯了原著者的合法權益,可聯系我們進行處理。