The method basically comes from the source code in the thinkphp, but has been modified by me
Copy Code code as follows:
<?php
/*
* @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. You can handle nested labels, but the limitation is that the property values in the tag are deleted
* @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 revision is also on the top, but the comment is off. Personally, I think this method is better than using regular-type methods.