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