PHP字串函數大全

來源:互聯網
上載者:User

1尋找字元位置函數:

strpos($str,search,[int]):尋找search在$str中的第一次位置從int開始;

stripos($str,search,[int]):函數返回字串在另一個字串中第一次出現的位置。該函數對大小寫不敏感

strrpos($str,search,[int]):尋找search在$str中的最後一次出現的位置從int

2、提取子字元函數(雙位元組)

submit($str,int start[,int length]):從$str中strat位置開始提取[length長度的字串]。

strstr($str1,$str2):從$str1(第一個的位置)搜尋$str2並從它開始截取到結束字串;若沒有則返回FALSE。

stristr() 功能同strstr,只是不區分大小寫。

strrchr() 從最後一次搜尋到的字元處返回;用處:取路徑中檔案名稱

3、替換字串

str_replace(search,replace,$str):從$str中尋找search用replace來替換

str_irreplace(search,replace,$str):

strtr($str,search,replace):這個函數中replace不能為"";

substr_replace($Str,$rep,$start[,length])$str原始字串,$rep替換後的新

字串,$start起始位置,$length替換的長度,該項可選

4、字元長度

int strlen($str)

5、比較字元函數

int strcmp($str1,$str2):$str1>=<$str2分別為正1,0,-1(字串比較)

strcasecmp() 同上(不分大小寫)

strnatcmp("4","14") 按自然排序比較字串

strnatcasecmp() 同上,(區分大小寫)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.