This article mainly introduces PHP code for converting HTML into text. if you need it, refer to the following 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 ($ s Earch, $ replace, $ document);?>