Remove HTML tags from php _php tutorial

Source: Internet
Author: User


Usually we use Htmlspecialchars () to filter the HTML, but the HTML characters escaped, the final display is the HTML source code.

You can use Strip_tags () to get rid of HTML tags.

$str = ' href ';
echo Htmlspecialchars ($STR);
echo Strip_tags ($STR);

?>

Many home pages have a small part of the article. Use Strip_tags () to get rid of HTML tags here. But we have to consider what the code is, because the normal cut field string can easily cut the last character into half.

/**
* Intercept Utf-8 string
* @since 2008.12.23
* @param string $str the truncated strings
* @param integer $start start position
* @param integer $length intercept Length (3 bytes per kanji)
*/
function Utf8_strcut ($str, $start, $length =null) {
Preg_match_all ('/./us ', $str, $match);
$chars = Is_null ($length)? Array_slice ($match [0], $start): Array_slice ($match [0], $start, $length);

Unset ($STR);

Return implode (", $chars);
}

http://www.bkjia.com/PHPjc/788518.html www.bkjia.com true http://www.bkjia.com/PHPjc/788518.html techarticle usually we use Htmlspecialchars () to filter the HTML, but the HTML characters escaped, the final display is the HTML source code. Use Strip_tags () to get rid of HTML tags ....

  • Related Article

    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.