Home > Backend Development > PHP Tutorial > PHP中怎么转义,大拿请帮忙!

PHP中怎么转义,大拿请帮忙!

WBOY
Release: 2016-06-13 11:55:03
Original
827 people have browsed it

PHP中如何转义,大拿请帮忙!!!急急急!!!
以下new_content是mysql中使用select返回的内容

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

结果如图:
tu1

';

请问如何将其中的<script>和</script>转换成<script>和</script>
------解决方案--------------------
htmlspecialchars这个函数可以转义
------解决方案--------------------
$new_content='<P>下面我给大家讲讲javascript函数:</P><PRE class=js name="code"><script> <BR>function show() <BR>{ <BR>alert("hello world"); <BR>} <BR></script>
Copy after login

结果如图:
tu1

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

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