PHP提供了各種字串函數來訪問和操作字串。 下麵給出了重要的PHP字串函數的列表。
1. PHP strtolower()函數
strtolower()
函數以小寫字母返回字串。
語法
string strtolower ( string $string )
示例
<?php
$str="My name is zaixian";
$str=strtolower($str);
echo $str;
?>
執行結果 -
my name is zaixian
2. PHP strtoupper()函數
strtoupper()
函數以大寫字母返回字串。
語法
string strtoupper ( string $string )
示例
<?php
$str="My name is zaixian";
$str=strtolower($str);
echo $str;
?>
執行結果 -
MY NAME IS zaixian
3. PHP ucfirst()函數
ucfirst()
函數返回將字串的第一個字元轉換為大寫。 它不改變其他字元的大小寫。
示例
<?php
$str="my name is zaixian";
$str=ucfirst($str);
echo $str;
?>
執行結果 -
My name is zaixian
4. PHP lcfirst()函數
lcfirst()
函數返回將第一個字元轉換為小寫的字串。 它不改變其他字元的情況。
語法
string lcfirst ( string $str )
示例
<?php
$str="MY name IS zaixian";
$str=lcfirst($str);
echo $str;
?>
執行結果 -
mY name IS zaixian
5. PHP ucwords()函數
ucwords()
函數返回將字串每個單詞的第一個字元轉換為大寫。
語法
string ucwords ( string $str )
示例
<?php
$str="my name is max su";
$str=ucwords($str);
echo $str;
?>
執行結果 -
My Name Is Max Su
6. PHP strrev()函數
strrev()
函數返回字串反轉的形式。
語法
string strrev ( string $string )
示例
<?php
$str="my name is Maxsu jaiswal";
$str=strrev($str);
echo $str;
?>
執行結果 -
lawsiaj oonoS si eman ym
7. PHP strlen()函數
strlen()
函數返回字串的長度。
語法
int strlen ( string $string )
示例
<?php
$str="my name is Max su";
$len=strlen($str);
echo $len;
?>
執行結果 -
16