PHP String strtoupper()函數(shù)
strtoupper()是PHP最受歡迎的函數(shù)之一,廣泛用于將字符串轉(zhuǎn)換為大寫。愛掏網(wǎng) - it200.com它以一個字符串作為參數(shù),并將該字符串中的所有小寫英文字母轉(zhuǎn)換為大寫。愛掏網(wǎng) - it200.com字符串的其他字符,如數(shù)字和特殊字符,保持不變。愛掏網(wǎng) - it200.com PHP 4+ 版本支持此函數(shù)。愛掏網(wǎng) - it200.com
注意:strtoupper()是一個二進制安全的函數(shù)。愛掏網(wǎng) - it200.com
PHP還有一些與strtoupper()函數(shù)相似的其他函數(shù):
- strtolower() - 將字符串轉(zhuǎn)換為小寫。愛掏網(wǎng) - it200.com
- lcfirst() - 將字符串的第一個字符轉(zhuǎn)換為小寫。愛掏網(wǎng) - it200.com
- ucfirst() - 將字符串的第一個字符轉(zhuǎn)換為大寫。愛掏網(wǎng) - it200.com
- ucwords() - 將字符串中每個單詞的第一個字符轉(zhuǎn)換為大寫。愛掏網(wǎng) - it200.com
語法
strtoupper()函數(shù)的語法如下,它只有一個字符串參數(shù)。愛掏網(wǎng) - it200.com
strtoupper($string)
參數(shù)
$string(必需): 這是該函數(shù)的一個必需參數(shù),用于指定要轉(zhuǎn)換為大寫的字符串。愛掏網(wǎng) - it200.com簡單來說,它是一個被轉(zhuǎn)換為大寫的字符串。愛掏網(wǎng) - it200.com
返回值
返回轉(zhuǎn)換為大寫的字符串。愛掏網(wǎng) - it200.com
示例
strtoupper()是PHP中常用的函數(shù)。愛掏網(wǎng) - it200.com下面給出一些示例。愛掏網(wǎng) - it200.com通過這些示例,我們可以實際理解該函數(shù)的工作原理。愛掏網(wǎng) - it200.com
示例1:
<?php
//original string
input_str = "WelCoMe to JavaTPoint";
//string converted into lowercaseresult_str = strtoupper(input_str);
echoresult_str;
?>
輸出:
WELCOME TO JAVATPOINT
示例2
<?php
//original string
input_str = "hie! I'm Gunjan Garg.";
echo "<b>String before conversion: </b>".input_str;
echo "</br>";
//string converted into lowercase
result_str = strtoupper(input_str);
echo "<b>String after conversion: </b>". $result_str;
?>
輸出:
String before conversion: hie! I'm Gunjan Garg.
String after conversion: HIE! I'M GUNJAN GARG.
示例3
在這個示例中,我們將看到在對字符串應(yīng)用strtoupper()函數(shù)之后,特殊字符保持不變。愛掏網(wǎng) - it200.com它只轉(zhuǎn)換字母字符,而特殊符號沒有任何改變。愛掏網(wǎng) - it200.com
<?php
input_str1 = "!, @, %,, and # are the special symbols.";
echo "<b>String before conversion: </b>". input_str1;
echo "</br>";
//string converted into lowercaseresult_str = strtoupper(input_str1);
echo "<b>String after conversion: </b>".result_str;
?>
輸出:
String before conversion: !, @, %, , and # are the special symbols.
String after conversion: !, @, %,, AND # ARE THE SPECIAL SYMBOLS.