使用 preg_match 查找字符串是否包含脚本标签 [英] Use preg_match to find if string contains script-tags

查看:53
本文介绍了使用 preg_match 查找字符串是否包含脚本标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何编写与 PHP 的 preg_match 函数一起使用的模式来检查字符串是否包含脚本标签?

How do I write a pattern to use with PHP's preg_match function to check if a string containing script-tags?

推荐答案

你想逃避他们吗?如果是这样,请尝试以下(未测试)

Are you trying to escape them? if so try the following (not tested)

$string=str_replace(array("&", "<", ">"), array("&amp;", "&lt;", "&gt;"), $string);

通过这种方式,您的攻击者将会有一个惊喜.

With this way a surprise will be waiting your attackers.

这篇关于使用 preg_match 查找字符串是否包含脚本标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆