<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                數組、字符串和數據庫是我們函數里面最、最、最常用的三類函數,數組和數據庫我們現在還沒有講到,等講到的時候我們再來和大家細說。 當然PHP的字符串函數也有很多。我們最常使用的兩個系列的字符串: 1. 單字節字符串處理函數 2. 多字節字符串處理函數 3. 字符串編碼轉換函數 我們來說說為什么要學這么多函數: 1. 我們學的是中文,是雙字節或者三字節的。老外的函數只能處理英文和數字這些單字節的字符串處理不鳥中文。達不到我們的功能需求 2. 有的時候需要做不同字符編碼間的轉換,例如:把GBK的轉為UTF-8 3. 英文這些字符在電腦里又是必須要處理的 因此,我們要學三個類型的常用字符串函數。 我們來貼個PHP手冊的鏈接給大家看看: 1. 多字節iconv_* 系列:http://phpbook.phpxy.com/book.iconv.html 2. 多字節mb_* 系列:http://php.net/manual/zh/book.mbstring.php 3. 處理英文系列:http://phpbook.phpxy.com/book.strings.html 看了這三個鏈接是不是又被嚇著了? ![document/2015-08-18/55d341cc9f228](http://box.kancloud.cn/document_2015-08-18_55d341cc9f228.png) 當然,你不用學這么多。PHP學院已經幫你把最常用的,需要強制背誦的準備好了。 ![document/2015-08-18/55d34215d28bb](http://box.kancloud.cn/document_2015-08-18_55d34215d28bb.png) 之前都教過大家用,那你開始背函數吧。 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轉義為<br>標簽 | echo nl2br("One line.\nAnother line.");| | strip_tags()| 剝去 HTML、XML 以及 PHP 的標簽|echo strip_tags("Hello <b>world!</b>"); | | 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 | | | | mb_substr|獲取字符串的部分 | 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是三字節,一個漢字占用三個字節長度的存儲空間。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看