Home  >  Article  >  Backend Development  >  PHP中如何转义,大拿请帮忙!

PHP中如何转义,大拿请帮忙!

WBOY
WBOYOriginal
2016-06-23 13:58:49839browse

以下new_content是mysql中使用select返回的内容

$new_content='<P>下面我给大家讲讲javascript函数:</P><PRE class=js name="code"><script> <BR>function show() <BR>{ <BR>alert("hello world"); <BR>} <BR></script>
 

 结果如图:
PHP中如何转义,大拿请帮忙!

';
请问如何将其中的<script>和</script>转换成3f1c4e4b6b16bbbd69b2ee476dc4f83a和2cacc6d41bbb37262a98f745aa00fbf0


回复讨论(解决方案)

htmlspecialchars这个函数可以转义

$new_content='<P>下面我给大家讲讲javascript函数:</P><PRE class=js name="code"><script> <BR>function show() <BR>{ <BR>alert("hello world"); <BR>} <BR></script>
 

 结果如图:
PHP中如何转义,大拿请帮忙!

';var_dump(preg_replace_callback('//i', function($r){return htmlentities($r[0]);}, $new_content)) ;

2#大牛,你好,能不能请你回答一下这个问题,http://bbs.csdn.net/topics/390762602,这是问题详细的阐述,真的搞不懂啊!!!php读数据库肿么了,,,,

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