The method basically comes from the source code in the thinkphp, but I changed it a bit.
Copy CodeThe code is as follows:
/*
* @Description: Delete HTML tags and get plain text. can handle nested labels
*
*/
Class deletehtmltags{
Private $filename;
function __construct ($filename = ' c:/appserv/www/text.txt ') {
$this->filename = $filename;
}
/**
* Delete HTML tags to get plain text. can handle nested tags, the limitation is that the value of the property within the label will be removed
* @access Public
* @param string $string The 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 on the top, just commented out. Personally, this method is better than using regular methods.
http://www.bkjia.com/PHPjc/762211.html www.bkjia.com true http://www.bkjia.com/PHPjc/762211.html techarticle The method is basically from the source code in thinkphp, but I changed the copy code as follows: PHP/* * @Description: Delete HTML tags, get plain text. can handle nested tags ...