PHP code to empty the HTML tags in the string

Source: Internet
Author: User
Keywords Network programming PHP tutorial
Tags array code function html network network programming php php tutorial

This article describes PHP empty string html tags Tag: HTML, HTML, HTML Category: html


function clear_html_label ($ html)
{
$ search = array ("'<script [^>] *?>. *? </ script>' si", '' <[/!] *? [^ <>] *?> 'si', ' ([rn]) [s] + '",' '& (quot | # 34);' i ' 'i', '' & gt; # 62; 'i', '' & (nbsp | # 160); 'i' 'i', '' & (copy | # 169); 'i', '' & # (d +); 'e ") ;
$ replace = array ("", "", "1", "", "&", "<", ">", "", chr (161), chr (169), "chr (1)");

return preg_replace ($ search, $ replace, $ html);
}

// Instance application

$ string = 'aaa <br /> <script> fdsafsa';
echo clear_html_label ($ string); // aaa fdsafsa

// Take advantage of the php strip_tags (); www.zzarea.com
echo strip_tags ($ string); // aaa fdsafsa


to sum up,
The results of the above two functions are identical, one is user-defined filter all html function, one is php built-in function, but in effect the php strip_tags () function, it must be much higher. At least why I will not say much.

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.