PHP - strtolower() 函式



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

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

語法

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

strtolower(string $str): string

引數

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

  • str: 需要轉換為小寫的輸入字串。

返回值

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

示例 1

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

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

輸出

上述程式產生以下輸出:

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

示例 2

以下是使用 PHP strtolower() 函式的另一個示例。此函式將給定字串“Hello World!”中的所有字母字元轉換為小寫:

<?php
   $str = "Hello World!";
   echo "The given string: $str";
   echo "\nThe string after converting into lowercase: ";
   #using strtolower() function
   echo strtolower($str);
?>

輸出

以下是上述程式的輸出:

The given string: Hello World!
The string after converting into lowercase: hello world!

示例 3

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

<?php
   $str = "hey!, how are you";
   echo "The given string: $str";
   echo "\nThe string after converting into lowercase: ";
   #using strtolower() function
   echo strtolower($str);
?>

輸出

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

The given string: hey!, how are you
The string after converting into lowercase: hey!, how are you
php_function_reference.htm
廣告