欧美亚洲中文,在线国自产视频,欧洲一区在线观看视频,亚洲综合中文字幕在线观看

      1. <dfn id="rfwes"></dfn>
          <object id="rfwes"></object>
        1. 站長(zhǎng)資訊網(wǎng)
          最全最豐富的資訊網(wǎng)站

          php如何去除html,空格,換行,提取純文字

          php去除html,空格,換行,提取純文字的方法:1、清除字符串兩邊的空格,代碼為【$str = trim($str)】;2、匹配html中的空格,代碼為【$str = preg_replace("/ /","",$str)】。

          php如何去除html,空格,換行,提取純文字

          php去除html,空格,換行,提取純文字的方法:

          方法一:

          function DeleteHtml($str)  {      $str = trim($str); //清除字符串兩邊的空格     $str = preg_replace("/t/","",$str); //使用正則表達(dá)式替換內(nèi)容,如:空格,換行,并將替換為空。     $str = preg_replace("/rn/","",$str);      $str = preg_replace("/r/","",$str);      $str = preg_replace("/n/","",$str);      $str = preg_replace("/ /","",$str);     $str = preg_replace("/  /","",$str);  //匹配html中的空格     return trim($str); //返回字符串 }

          調(diào)用方法

          DeleteHtml($str);

          $str 為需要清除的頁(yè)面字符串

          方法二:

          function DeleteHtml($str)  {      $str = trim($str); //清除字符串兩邊的空格     $str = strip_tags($str,""); //利用php自帶的函數(shù)清除html格式     $str = preg_replace("/t/","",$str); //使用正則表達(dá)式替換內(nèi)容,如:空格,換行,并將替換為空。     $str = preg_replace("/rn/","",$str);      $str = preg_replace("/r/","",$str);      $str = preg_replace("/n/","",$str);      $str = preg_replace("/ /","",$str);     $str = preg_replace("/  /","",$str);  //匹配html中的空格     return trim($str); //返回字符串 }

          方法三:

          去除字符串內(nèi)部的空行:

          $str = preg_replace("/(s*?r?ns*?)+/","n",$str);

          去除全部的空行,包括內(nèi)部和頭尾:

          $str = preg_replace('/($s*$)|(^s*^)/m', '',$str);

          相關(guān)學(xué)習(xí)推薦:php編程(視頻)

          贊(1)
          分享到: 更多 (0)
          網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)