Home > Backend Development > PHP Tutorial > php Convert HTML to text_PHP tutorial

php Convert HTML to text_PHP tutorial

WBOY
Release: 2016-07-20 11:17:35
Original
966 people have browsed it

 

php
// $document should contain an HTML document.

// This example will remove HTML tags and javascript code

// and whitespace characters. We will also add some common

// HTML entities are converted into corresponding text.


$search = array ("']*?>.*?'si", // Remove javascript
"'<[/!]*?[^<>]*?>'si", // Remove the HTML tag
"'([rn])[s]+'", // Remove whitespace characters
"'&(quot|#34);'i", // Replace 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 as PHP code

$replace = array ("",
"",
"1",
""",
"&",
"<",
">",
" ",
chr(161),
chr(162),
chr(163),
chr(169),
"chr(1)");

$text = preg_replace ($search, $replace, $document);
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/371955.htmlTechArticle? php // $document should contain an HTML document. // This example will remove HTML tags, javascript code // and whitespace characters. It will also convert some common // HTML entities into corresponding text...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template