]*?>.*?'si",);" Regular matching; 3. Use the "preg_replace($search, $replace, $document);" method to delete all js in the content."/> ]*?>.*?'si",);" Regular matching; 3. Use the "preg_replace($search, $replace, $document);" method to delete all js in the content.">

Home >Backend Development >PHP Problem >How to delete all js content in php

How to delete all js content in php

藏色散人
藏色散人Original
2022-10-21 10:28:581100browse

php删除内容所有js的方法:1、创建一个PHP示例文件;2、通过“array ("'<script>]*?>.*?&#39;si",);”方式实现js的正则匹配;3、通过“preg_replace($search, $replace, $document);”方法删除内容所有js即可。</script>[^>

How to delete all js content in php

本教程操作环境:windows7系统、PHP8.1版、Dell G3电脑。

php 怎么删除内容所有 js?

php正则去除网页中所有的html,js,css,注释

如下所示:

$search = array ("&#39;<script[^>]*?>.*?</script>&#39;si", // 去掉 javascript
 "&#39;<style[^>]*?>.*?</style>&#39;si",  // 去掉 css
 "&#39;<[/!]*?[^<>]*?>&#39;si",      // 去掉 HTML 标记
 "&#39;<!--[/!]*?[^<>]*?>&#39;si",      // 去掉 注释 标记
 "&#39;([rn])[s]+&#39;",  // 去掉空白字符
 "&#39;&(quot|#34);&#39;i",  // 替换 HTML 实体
 
 "&#39;&(amp|#38);&#39;i",
 "&#39;&(lt|#60);&#39;i",
 "&#39;&(gt|#62);&#39;i",
 "&#39;&(nbsp|#160);&#39;i",
 "&#39;&(iexcl|#161);&#39;i",
 "&#39;&(cent|#162);&#39;i",
 "&#39;&(pound|#163);&#39;i",
 "&#39;&(copy|#169);&#39;i",
 "&#39;&#(d+);&#39;e");   // 作为 PHP 代码运行
  
$replace = array ("",
 "",
 "",
 "",
 "\1",
 "\"",
 "&",
 "<", 
 ">",
 " ",
 chr(161),
 chr(162),
 chr(163),
 chr(169),
 "chr(\1)");
//$document为需要处理字符串,如果来源为文件可以$document = file_get_contents($filename);
$out = preg_replace($search, $replace, $document);

也可以使用php的内置函数strip_tags()清除html,js,注释等标记

推荐学习:《PHP视频教程

The above is the detailed content of How to delete all js content in php. For more information, please follow other related articles on the PHP Chinese website!

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