The method basically comes from the source code in THinkphp, but I modified it a bit
Copy the code The code is as follows:
php
/*
*@Description: Remove HTML tags and get plain text. Can handle nested tags
*
*/
class deleteHtmlTags{
private $filename;
function __construct($filename='C:/AppServ/www /text.txt'){
$this->filename = $filename;
}
/**
* Remove html tags and get plain text. Nested tags can be processed, but the limitation is that even the attribute values in the tags will be deleted
* @access public
* @param string $string html to be processed
* @return string
*/
public function deletehtmltags(){
$content = $this->contentGet();
while(strstr($content, '>')){
$currentBegin = strpos($content, '<');
$ currentEnd = strpos($content, '>');
$cha = $currentEnd - $currentBegin - 1;
$tmpStringBegin = @substr($content, 0, $currentBegin);
// $tmpStringMiddle = @substr($content, $currentBegin + 1, $cha);
$tmpStringEnd = @substr($content, $currentEnd + 1, strlen($content));
// $content = $tmpStringBegin.$tmpStringMiddle.$tmpStringEnd;
$content = $tmpStringBegin.$tmpStringEnd;
}
return $content;
}
private function contentGet(){
$fd = fopen($this->filename, 'r');
$content = fread($fd, filesize($this->filename));
fclose($fd);
return $content;
}
}
$deleteHtml = new deleteHtmlTags();
$content = $deleteHtml->deletehtmltags();
echo $content;
?>
The modified part is also above, just commented out. Personally, I think this method is better than using regular methods.
http://www.bkjia.com/PHPjc/762211.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/762211.htmlTechArticleThe method basically comes from the source code in THinkphp, but it was modified by me. The copy code is as follows: ?php /* *@Description: Remove HTML tags and get plain text. Can handle nested tags...