PHP常用字串處置函數

來源:互聯網
上載者:User
PHP常用字串處理函數

PHP字串操作常用函數

/*

* 確定字串長度

* int strlen(string str)

* 比較兩個字串

* 1、strcmp函數對兩個字串進行二進位安全的比較,並區分大小寫

* int strcmp(string str1,string str2)

* 2、以不區分大小寫方式比較兩個字串

* int strcasecmp(string str1,string str2)

* 3、求兩個字串相同部分

* int strspn(string str1,string str2)

* 4、求兩個字串的不同部分

* int strcspn(string str1,string str2)

* 處理字串大小寫

* 1、將字串全部轉換為小寫

* string strtolower(string str)

* 2、將字串全部轉化為大寫

* string strtoupper(string str)

* 3、將字串第一個字元大寫

* string ucfirst(string str)

* 4、將字串中的每個單詞變成大寫

* string ucword(string str)

* 字串與HTML相互轉換

* 1、將分行符號轉換為HTML終止標記

* string bl2br(string str)

* 2、將特殊字元轉換wieldHTML等價形式

* string htmlentities(string str[,int quote_style[,int charset]])

* 3、使用特殊的HTML字元用於其他目的

* string htmlspecialchars(string str[,int quote_style[,string charset]])

* 4、將文本轉換為HTML等價形式

* array get_html_translaction_table(int table[,int quote_style])

* 5、建立一個自訂的轉換清單

* string strtr(string str,array replacements)

* 6、將HTML轉換為純文字

* string strip_tags(string str[,string allowable_tags])

* Regex函數的替代函數

* 1、strtok函數根據預定義的字串列表來解析字串

* string strtok(string str,string tonens)

* 2、根據預定義的定界符分析字串

* array explode(string separator,string str[,int limit])

* 3、將數群組轉換為字串

* string implode(string delimiter, array array)

* 4、解析複雜的字串

* int strpos(string str,string substr[,int offset])

* 5、找到字串的最後一次出現

* int strrpos(string str,char substr[,offset])

* 6、用另外一個字串替代字串的所有執行個體

* mixed str_replace(string occurrence,mixed replacement,mixed str[,int count])

* 7、擷取字串的一部分strstr返回字串中預定義字串第一次出現開始的剩餘部分

* string strstr(string str,string occurrence)

* 8、根據預定義的位移返回字串一部分

* string substr(string str,int start[,ing length])

* 9、確定字串出現的頻率

* int substr_count(string str,string substring)

* 10、用另一個字串替換一個字串的一部分

* string substr_replace(string str,string replacement,int start[,int length])

* 填充和剔除字串

* 1、從字串開始出裁剪字元

* string ltrim(string str[,string charliset])

* 2、從字串結尾裁剪字元

* string rtrim(string str[,string charliset])

* 3、從字串兩端裁剪字元

* string trim(string str[,string charliset])

* 4、填充字串

* string str_pad(string str,int length[,string pad_string[,int pad_type]])

* 字元和單詞計數

* 1、字串中字元計數

* mixed count_chars(string str[,mode])

* 2、字串中單詞總數計數

* mixed str_word_count(string str[,int format])

*/
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.