Remove HTML tags get plain text to handle nested tags _php tutorial

Source: Internet
Author: User
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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.