Home > Backend Development > PHP Tutorial > Example of removing HTML tags in php_PHP tutorial

Example of removing HTML tags in php_PHP tutorial

WBOY
Release: 2016-07-13 10:25:32
Original
772 people have browsed it

Example 1. PHP’s built-in function can remove/delete HTML tags/codes in strings.
strip_tags(string,allow): Function strips HTML, XML and PHP tags.
Parameters: string, required, specifies the string to be checked; allow, optional, specifies the tags that are allowed to exist, and these tags will not be deleted.

Copy code The code is as follows:

$str = 'Guo bowl and pan -PHP';
$str1 = strip_tags($str);        / / Keep the tag
echo $str1; // Output Guo bowl and pan - PHP
echo $str2; // The style is different

Example 2, clear certain attribute codes in HTML tag strings

Use PHP to process the HTML code of the article read from the database, and then use regular expressions to match and modify the code. After saving the code, use the static generation function The modified HTML page can be generated.
Because the code we generate is already processed code, it will not affect the loading speed of the HTML page.
The specific [sample code] is as follows:

Copy code The code is as follows:
$ str = "";
$str = preg_replace('#onclick =([sS]*)"#','',$str);
// Please note that there is a double quotation mark in front of the # symbol, which represents the end of the code
print($str);
? >

http://www.bkjia.com/PHPjc/825086.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/825086.htmlTechArticleExample 1. PHP’s built-in function can remove/delete HTML tags/codes in strings. strip_tags(string,allow): Function strips HTML, XML and PHP tags. Parameters: string, required, specified...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template