亚洲最大看欧美片,亚洲图揄拍自拍另类图片,欧美精品v国产精品v呦,日本在线精品视频免费

  • 站長資訊網(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); //使用正則表達式替換內(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 為需要清除的頁面字符串

    方法二:

    function DeleteHtml($str)  {      $str = trim($str); //清除字符串兩邊的空格     $str = strip_tags($str,""); //利用php自帶的函數(shù)清除html格式     $str = preg_replace("/t/","",$str); //使用正則表達式替換內(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)學習推薦:php編程(視頻)

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