PHP Filter function code for HTML tags _php tutorial

Source: Internet
Author: User
Tags ord
PHP Filter function code for HTML tags this article provides four of PHP filtering HTML tag function code, one of the simplest use of PHP's own function strip_tags to filter all HTML tags, method two using regular expressions to filter the HTML tags, The third method is to clear the HTML tags of the user-defined function, according to the ASCII encoding value to determine whether to filter the letter.

PHP Tutorial Filter function code for HTML tags
This article provides four of PHP filtering HTML tags using the function code, one of the simplest use of PHP's own function strip_tags to filter all HTML tags, method two use regular expressions to filter HTML tags, method Three is to clear the HTML tag user-defined function, Determines whether the letter is re-filtered according to the ASCII encoded value.
*/
The most straightforward way to filter HTML

Strip_tags ();

Method two using regular filter
function _filter ($string) {
return Str_replace (Array ("n", "RN", "R", ""), Array ('
','
','
', '), Strip_tags ($string, '

'));
}

Regular two

preg_replace ('/(
) {1,}/is ', '
', $STR);


Regular three

function delhtml ($STR) {//Clear HTML tags
$st =-1; Begin
$et =-1; End
$stmp =array ();
$stmp []= "";
$len =strlen ($STR);
for ($i =0; $i < $len; $i + +) {
$ss =substr ($str, $i, 1);
if (Ord ($SS) ==60) {//ord ("<") ==60
$st = $i;
}
if (Ord ($SS) ==62) {//ord (">") ==62
$et = $i;
if ($st!=-1) {
$stmp []=substr ($str, $st, $et-$st + 1);
}
}
}
$str =str_replace ($stmp, "", $str);
return $str;
}
//

$str = '


www.bkjia.com <> < a=""> />

';
$reg = '/( | ) |<.+?>/i ';
Echo preg_replace ($reg, ' $ ', $str); <>


http://www.bkjia.com/PHPjc/445430.html www.bkjia.com true http://www.bkjia.com/PHPjc/445430.html techarticle PHP Filter function code for HTML tags this article provides four code to filter HTML tags using PHP, the simplest way to use PHP's own function strip_tags to filter all HTML 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.