Remove HTML tags

Source: Internet
Author: User

PHP strip_tags () function

 

Definition and usage

The strip_tags () function removes tags from HTML, XML, and PHP.

Syntax
strip_tags(string,allow)
Parameters Description
String Required. Specifies the string to be checked.
Allow Optional. The label that is allowed. These tags are not deleted.
Tips and comments

Note: This function will always strip HTML comments. This failsAllowParameter change.

 

 

Example 1
<?phpecho strip_tags("Hello <b>world!</b>");?>

Output: Hello world!

Example 2
<?phpecho strip_tags("Hello <b><i>world!</i></b>","<b>");?>

Output: HelloWorld!

Bytes --------------------------------------------------------------------------------------------------

The following are other online search references:

1. User-Defined Functions

Function delhtmlflag ($ document)
{
// Replace the HTML tag with regular expressions. The function is the same as dealhtml. It is from the PHP manual.
/* $ Document should contain an HTML document.
* In this example, the HTML Tag and JavaScript code are removed.
* And blank characters. Some common
* HTML objects are converted into corresponding text.
*/
$ Search = array ("'<SCRIPT [^>] *?> .*? </SCRIPT> 'si ", // remove Javascript
"'<[//!] *? [^ <>] *?> 'Si ", // remove the HTML Tag
"'([/R/n]) [/S] +'", // remove white space characters
"'& (Quot | #34);' I", // replaces the HTML Object
"'& (Amp | #38);' I ",
"'& (LT | #60);' I ",
"'& (GT | #62);' I ",
"'& (Nbsp | #160);' I ",
"'& (Iexcl | #161);' I ",
"'& (Cent | #162);' I ",
"'& (Pound | #163);' I ",
"'& (Copy | #169);' I ",
"'& # (/D +); 'E"); // run as PHP code

$ Replace = array ("",
"",
"// 1 ",
"/"",
"&",
"<",
"> ",
"",
CHR (1, 161 ),
CHR (1, 162 ),
CHR (1, 163 ),
CHR (1, 169 ),
"CHR (// 1 )");
$ Text = preg_replace ($ search, $ replace, $ document );
Return $ text;
}

 

 

2. php htmlspecialchars () function

 

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.