欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

php實現(xiàn)轉(zhuǎn)換html格式為文本格式的方法

 更新時間:2016年05月16日 11:42:34   作者:cclehui  
這篇文章主要介紹了php實現(xiàn)轉(zhuǎn)換html格式為文本格式的方法,通過一個自定義函數(shù)實現(xiàn)針對HTML標簽的過濾,涉及php正則替換的相關(guān)操作技巧,需要的朋友可以參考下

本文實例講述了php實現(xiàn)轉(zhuǎn)換html格式為文本格式的方法。分享給大家供大家參考,具體如下:

有時候需要轉(zhuǎn)換html格式的字符串為文本,但又需要保持一定的格式,比如要求段落變成的分段格式就可以用下面這個函數(shù)

function html2text($str){
 $str = preg_replace("/<style .*?<\\/style>/is", "", $str);
 $str = preg_replace("/<script .*?<\\/script>/is", "", $str);
 $str = preg_replace("/<br \\s*\\/>/i", ">>>>", $str);
 $str = preg_replace("/<\\/?p>/i", ">>>>", $str);
 $str = preg_replace("/<\\/?td>/i", "", $str);
 $str = preg_replace("/<\\/?div>/i", ">>>>", $str);
 $str = preg_replace("/<\\/?blockquote>/i", "", $str);
 $str = preg_replace("/<\\/?li>/i", ">>>>", $str);
 $str = preg_replace("/ /i", " ", $str);
 $str = preg_replace("/ /i", " ", $str);
 $str = preg_replace("/&/i", "&", $str);
 $str = preg_replace("/&/i", "&", $str);
 $str = preg_replace("/</i", "<", $str);
 $str = preg_replace("/</i", "<", $str);
 $str = preg_replace("/“/i", '"', $str);
 $str = preg_replace("/&ldquo/i", '"', $str);
 $str = preg_replace("/‘/i", "'", $str);
 $str = preg_replace("/&lsquo/i", "'", $str);
 $str = preg_replace("/'/i", "'", $str);
 $str = preg_replace("/&rsquo/i", "'", $str);
 $str = preg_replace("/>/i", ">", $str);
 $str = preg_replace("/>/i", ">", $str);
 $str = preg_replace("/”/i", '"', $str);
 $str = preg_replace("/&rdquo/i", '"', $str);
 $str = strip_tags($str);
 $str = html_entity_decode($str, ENT_QUOTES, "utf-8");
 $str = preg_replace("/&#.*?;/i", "", $str);
 return $str;
}

PS:小編在這里推薦一款本站的php格式化美化的排版工具幫助大家在以后的PHP程序設計中進行代碼排版:
 
php代碼在線格式化美化工具:http://tools.jb51.net/code/phpformat

對于代碼及編碼轉(zhuǎn)換感興趣的朋友還可參考本站在線工具:

在線編碼轉(zhuǎn)換工具(utf-8/utf-32/Punycode/Base64):

http://tools.jb51.net/transcoding/decode_encode_tool

在線UBB/HTML代碼轉(zhuǎn)換工具:

http://tools.jb51.net/transcoding/ubb2html

中文繁體字簡體字轉(zhuǎn)換(繁簡轉(zhuǎn)換)工具:

http://tools.jb51.net/transcoding/convertzh

在線圖片轉(zhuǎn)換BASE64工具:

http://tools.jb51.net/transcoding/img2base64

更多關(guān)于PHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《PHP數(shù)組(Array)操作技巧大全》、《php排序算法總結(jié)》、《PHP常用遍歷算法與技巧總結(jié)》、《PHP數(shù)據(jù)結(jié)構(gòu)與算法教程》、《php程序設計算法總結(jié)》、《PHP數(shù)學運算技巧總結(jié)》、《php正則表達式用法總結(jié)》、《PHP運算與運算符用法總結(jié)》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫操作技巧匯總

希望本文所述對大家PHP程序設計有所幫助。

相關(guān)文章

最新評論