Remove HTML tags from php

Source: Internet
Author: User
Tags html tags integer string


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

Use Strip_tags () to get rid of HTML tags.

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

?>

Many of the home page has a small part of the article. Use Strip_tags () to remove HTML tags here. But we also have to consider what the code is, because the normal cutting field string is easy to cut the last character into half.

/**
* Intercept Utf-8 string
* @since 2008.12.23
* @param string $str intercepted
* @param integer $start starting 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);
}



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.