一、strlen字符串長度: php
$a='1234abc';
echo strlen($a);
函數
二、strtoupper與ucwords大小寫轉換: spa
$a='i am A student.';
echo strtoupper($a)."<br>"; // I AM A STUDENT.
echo strtolower($a)."<br>"; // i am a student.
echo ucfirst($a)."<br>"; // I am A student.
echo ucwords($a)."<br>"; // I Am A Student. code
三、substr字符串截取: 字符串
格式substr(string str,int start,int length); string
$a='i am A student.';
echo substr($a,0,1)." "; // i
echo substr($a,-1,1)." "; // .
echo substr($a,0)." "; // i am A student.
四、strstr與strrchr字符串查找: class
格式 strstr(string haystack,string needle); 語法
strrchr()函數獲取字符串(A)在另外一個字符串(B)中最後一次出現的位置,區分字母大小寫。語法格式與strstr相同。
word
<?php $a='i am A student.'; echo strstr($a,"am"); //am A student. echo strrchr($a,"t"); //t. ?>
五、str_ireplace字符串替換: co
格式str_ireplace(string search, string replace,string subject [,int &count])
其中參數search爲指定要查找的字符串;replace爲指定替換的值;subject爲指定查找的範圍;count爲可選參數,獲取執行替換的數量。
<?php $a='i am A student.'; $c=0; echo str_ireplace("i am A","I am a",$a); //I an a student. echo str_ireplace("t","T",$a,$c); //I am A sTudenT. echo $c; //2 ?>