PHP - strtoupper() 函式



PHP 的 strtoupper() 函式用於將給定字串中的所有字母字元(即 a 到 z)轉換為大寫。術語“大寫”指的是字母系列中的“大寫字母”字元,例如 A、B、C、…D。

如果給定的字串已經是大寫,則此函式不會影響原始字串,並將保持不變。

語法

以下是 PHP strtoupper() 函式的語法:

strtoupper(string $str): string

引數

此函式接受一個引數,如下所述:

  • string: 需要轉換為大寫的輸入字串。

返回值

此函式返回所有字母字元都已轉換為大寫的字串。

示例 1

以下是 PHP strtoupper() 函式的基本示例:

<?php
   $str = "tutorialspoint";
   echo "The given string: $str";
   echo "\nThe string after converting into uppercase: ";
   #using strtoupper() function
   echo strtoupper($str);
?>

輸出

上述程式產生以下輸出:

The given string: tutorialspoint
The string after converting into uppercase: TUTORIALSPOINT

示例 2

這是使用 PHP strtoupper() 函式的另一個示例。此函式將給定字串“hEllO WoRLd!”中的所有字母字元轉換為大寫:

<?php
   $str = "hEllO WoRLd!";
   echo "The given string: $str";
   echo "\nThe string after converting into uppercase: ";
   #using strtoupper() function
   echo strtoupper($str);
?>

輸出

以下是上述程式的輸出:

The given string: hEllO WoRLd!
The string after converting into uppercase: HELLO WORLD!

示例 3

如果給定的字串已經是大寫,則 PHP strtoupper() 函式不會影響原始字串,它將保持不變:

<?php
   $str = "HELLO FROM TP!";
   echo "The given string: $str";
   echo "\nThe string after converting into uppercase: ";
   #using strtoupper() function
   echo strtoupper($str);
?>

輸出

執行上述程式後,將顯示以下輸出:

The given string: HELLO FROM TP!
The string after converting into uppercase: HELLO FROM TP!
php_function_reference.htm
廣告
© . All rights reserved.