This article mainly introduces PHP code for converting HTML into text. For more information, see
This article mainly introduces PHP code for converting HTML into text. For more information, see
Core code:
<? Php // $ document should contain an HTML document. // In this example, the HTML Tag, javascript code //, and blank characters are removed. Some common // HTML objects are converted into corresponding text. $ Search = array ("' ] *?>. *? Script 'si ", // remove javascript" '<[\/\!] *? [^ <>] *?> 'Si ", // remove the HTML Tag" '([\ r \ n]) [\ s] + '", // remove the blank character "'& (quot | #34);' I", // Replace the HTML Entity "'& (amp | #38);' I ", "'& (lt | #60);' I", "'& (gt | #62);' I", "'& (nbsp | #160 ); 'I ","' & (iexcl | #161); 'I ","' & (cent | #162); 'I ", "'& (pound | #163);' I", "'& (copy | #169);' I", "'& # (\ d + ); 'E "); // run $ replace = array (" "," "," \ 1 ","\"","&", "<", ">", "", chr (161), chr (162), chr (163), "chr (\ 1) "); $ text = preg_replace ($ search, $ replace, $ document) ;?>
,