Home  >  Article  >  Backend Development  >  PHP completely filters HTML, JS, CSS and other tags_PHP tutorial

PHP completely filters HTML, JS, CSS and other tags_PHP tutorial

WBOY
WBOYOriginal
2016-07-21 15:47:591079browse

I remember writing an article before
php effectively filters html tags, js code, css style tags:

Copy the code The code is as follows:

$str = preg_replace( "@@is", "", $str );
$str = preg_replace( "@@is", "", $str );
$str = preg_replace( "@$str = preg_replace( "@<(.*?)>@is", "", $str );
?>

are all regular filtering HTML tags, but today they are not easy to use. The reason is that the tags are escaped. For example,
. This is what is displayed on the page. But the source file is displayed like this: "——But we can still deal with it, first decompile all the contents. Then filter it.
Copy code The code is as follows:

$str= htmlspecialchars_decode($str);

Using the htmlspecialchars_decode function is to convert the source file into a tag like <>. Then":
Copy code The code is as follows:

$str= preg_replace("/<(.*?)> ;/","",$str);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/319819.htmlTechArticleI remember I wrote an article before that php can effectively filter html tags, js code, css style tags: Copy code code As follows: ?php $str = preg_replace( "@script(.*?)/script@is", "", $str ); $str...
Statement:
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