亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

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

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

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

有時(shí)候需要轉(zhuǎn)換html格式的字符串為文本,但又需要保持一定的格式,比如要求段落變成的分段格式就可以用下面這個(gè)函數(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程序設(shè)計(jì)中進(jìn)行代碼排版:
 
php代碼在線格式化美化工具:http://tools.jb51.net/code/phpformat

對(duì)于代碼及編碼轉(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

中文繁體字簡(jiǎn)體字轉(zhuǎn)換(繁簡(jiǎ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程序設(shè)計(jì)算法總結(jié)》、《PHP數(shù)學(xué)運(yùn)算技巧總結(jié)》、《php正則表達(dá)式用法總結(jié)》、《PHP運(yùn)算與運(yùn)算符用法總結(jié)》、《php字符串(string)用法總結(jié)》及《php常見數(shù)據(jù)庫(kù)操作技巧匯總

希望本文所述對(duì)大家PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論