国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

php字符串中常用函數的總結(附示例)

2020-03-22 18:18:06
字體:
來源:轉載
供稿:網友

本篇文章給大家帶來的內容是關于php字符串中常用函數的總結(附示例),有一定的參考價值,有需要的朋友可以參考一下,希望對你有所幫助。

PHP常用函數:

函數名 trim() 刪除字符串兩端的空格或其他預定義字符 $str = /r/nHello World!/r/n echo trim($str); rtrim() 刪除字符串右邊的空格或其他預定義字符 $str = Hello World!/n/n echo rtrim($str); chop() rtrim()的別名 ltrim() 刪除字符串左邊的空格或其他預定義字符 $str = /r/nHello World! echo ltrim($str); dirname() 回路徑中的目錄部分(我們把它歸在了字符串函數里了) echo dirname( c:/testweb/home.php str_pad() 把字符串填充為指定的長度 $str = Hello World echo str_pad($str,20, . str_repeat() 重復使用指定字符串 echo str_repeat( . ,13); str_split() 把字符串分割到數組中 print_r(str_split( Hello )); strrev() 反轉字符串 echo strrev( Hello World! wordwrap() 按照指定長度對字符串進行折行處理 $str = An example on a long word is: Supercalifragulistic echo wordwrap($str,15); str_shuffle() 隨機地打亂字符串中所有字符 echo str_shuffle( Hello World parse_str() 將字符串解析成變量 parse_str( id=23 name=John%20Adams ,$myArray); print_r($myArray); number_format() 通過千位分組來格式化數字 echo number_format( 1000000 echo number_format( 1000000 ,2); echo number_format( 1000000 ,2, , , . strtolower() 字符串轉為小寫 echo strtolower( Hello WORLD! strtoupper() 字符串轉為大寫 echo strtoupper( Hello WORLD! ucfirst() 字符串首字母大寫 echo ucfirst( hello world ucwords() 字符串每個單詞首字符轉為大寫 echo ucwords( hello world htmlentities() 把字符轉為HTML實體 $str = John Adams echo htmlentities($str, ENT_COMPAT); htmlspecialchars() 預定義字符轉html編碼 nl2br() /n轉義為
echo nl2br( One line./nAnother line. strip_tags() 剝去 HTML、XML 以及 PHP 的標簽 echo strip_tags( Hello world! addcslashes() 在指定的字符前添加反斜線轉義字符串中字符 $str = Hello, my name is John Adams. echo $str; echo addcslashes($str, m stripcslashes() 刪除由addcslashes()添加的反斜線 echo stripcslashes( Hello, /my na/me is Kai Ji/m. addslashes() 指定預定義字符前添加反斜線 $str = Who s John Adams? echo addslashes($str); stripslashes() 刪除由addslashes()添加的轉義字符 echo stripslashes( Who/ s John Adams? quotemeta() 在字符串中某些預定義的字符前添加反斜線 $str = Hello world. (can you hear me?) echo quotemeta($str); chr() 從指定的 ASCII 值返回字符 echo chr(052); ord() 返回字符串第一個字符的 ASCII值 echo ord( hello strcasecmp() 不區分大小寫比較兩字符串 echo strcasecmp( Hello world! , HELLO WORLD! strcmp() 區分大小寫比較兩字符串 strncmp() 比較字符串前n個字符,區分大小寫 strncasecmp() 比較字符串前n個字符,不區分大小寫 int strncasecmp ( string $str1 , string $str2 , int $len ) strnatcmp() 自然順序法比較字符串長度,區分大小寫 int strnatcmp ( string $str1 , string $str2 ) strnatcasecmp() 自然順序法比較字符串長度,不區分大小寫 int strnatcasecmp ( string $str1 , string $str2 ) chunk_split() 將字符串分成小塊 str chunk_split(str $body[,int $len[,str $end]]) strtok() 切開字符串 str strtok(str $str,str $token) explode() 使用一個字符串為標志分割另一個字符串 array explode(str $sep,str $str[,int $limit]) implode() 同join,將數組值用預訂字符連接成字符串 string implode ( string $glue , array $pieces ) substr() 截取字符串 string substr ( string $string , int $start [, int $length ] ) str_replace() 字符串替換操作,區分大小寫 mix str_replace(mix $search,,mix $replace,mix $subject[,int $num]) str_ireplace() 字符串替換操作,不區分大小寫 mix str_ireplace ( mix $search , mix $replace , mix $subject [, int $count ] ) substr_count() 統計一個字符串,在另一個字符串中出現次數 int substr_count ( string $haystack , string $needle [, int $offset = 0 [, int $length ]] ) substr_replace() 替換字符串中某串為另一個字符串 mixed substr_replace ( mixed $string , string $replacement , int $start [, int $length ] ) similar_text() 返回兩字符串相同字符的數量 int similar_text(str $str1,str $str2) strchr() 返回一個字符串在另一個字符串中開始位置到結束的字符串 string strstr ( string $str, string $needle , bool $before_needle ) strrchr() 返回一個字符串在另一個字符串中最后一次出現位置開始到末尾的字符串 string strrchr ( string $haystack , mixed $needle ) stristr() 返回一個字符串在另一個字符串中開始位置到結束的字符串,不區分大小寫 string stristr ( string $haystack , mixed $needle [, bool $before_needle = false ] ) strtr() 轉換字符串中的某些字符 string strtr ( string $str , string $from , string $to ) strpos() 尋找字符串中某字符最先出現的位置 int strpos ( string $haystack , mixed $needle [, int $offset = 0 ] ) stripos() 尋找字符串中某字符最先出現的位置,不區分大小寫 int stripos ( string $haystack , string $needle [, int $offset ] ) strrpos() 尋找某字符串中某字符最后出現的位置 int strrpos ( string $haystack , string $needle [, int $offset = 0 ] ) strripos() 尋找某字符串中某字符最后出現的位置,不區分大小寫 int strripos ( string $haystack , string $needle [, int $offset ] ) strspn() 返回字符串中首次符合mask的子字符串長度 int strspn ( string $str1 , string $str2 [, int $start [, int $length ]] ) strcspn() 返回字符串中不符合mask的字符串的長度 int strcspn ( string $str1 , string $str2 [, int $start [, int $length ]] ) str_word_count() 統計字符串含有的單詞數 mix str_word_count(str $str,[]) strlen() 統計字符串長度 int strlen(str $str) count_chars() 統計字符串中所有字母出現次數(0..255) mixed count_chars ( string $string [, int $mode ] ) md5() 字符串md5編碼 $str = Hello echo md5($str) iconv
獲取字符串的部分 string mb_substr ( string $str , int $start [, int $length = NULL [, string $encoding = mb_internal_encoding() ]] ) mb_http_output 設置/獲取 HTTP 輸出字符編碼 mixed mb_http_output ([ string $encoding = mb_http_output() ] ) mb_strlen 獲取字符串的長度 mixed mb_strlen ( string $str [, string $encoding = mb_internal_encoding() ] ) iconv 字符串按要求的字符編碼來轉換 string iconv ( string $in_charset , string $out_charset , string $str ) iconv_substr 截取字符串的部分 iconv_get_encoding 獲取 iconv 擴展的內部配置變量 mb_substr_count 統計字符串出現的次數 mb_check_encoding 檢查字符串在指定的編碼里是否有效 mb_strrpos 查找字符串在一個字符串中最后出現的位置 mb_split 使用正則表達式分割多字節字符串 parse_url 解釋URL成為一個數組

注:mb_* 和iconv_* 他們可以處理多字節字符,例如:中文。

中文主要用的是GBK和utf-8兩種編碼格式。
GBK和utf-8是兩個不同的編碼委員會對于漢字進行的編碼的標準。

他們規定GBK是雙字節,也就是一個漢字占用2Bytes。
utf-8是三字節,一個漢字占用三個字節長度的存儲空間。

以上就是php字符串中常用函數的總結(附示例)的詳細內容,PHP教程

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 和硕县| 云林县| 铜鼓县| 孝昌县| 凉山| 深州市| 双辽市| 固阳县| 荆州市| 积石山| 凤城市| 朝阳县| 阿勒泰市| 乌兰浩特市| 化德县| 屏南县| 南开区| 桃江县| 东乌珠穆沁旗| 时尚| 绍兴市| 潜山县| 尼勒克县| 甘洛县| 阿荣旗| 绥中县| 商丘市| 清新县| 滦平县| 屏东县| 合江县| 舟山市| 务川| 云阳县| 磴口县| 昌邑市| 开远市| 康马县| 容城县| 新源县| 威信县|