htmlspecialchars()函数

htmlspecialchars()函数,把 < 和 > 转换为实体,常用于防止浏览器将其用作 HTML 元素。

 1  <!DOCTYPE html>
 2 <html>
 3 <body>
 4 
 5 <?php
 6 $str = "This is some <b>bold</b> text.";
 7 echo htmlspecialchars($str);
 8 ?>
 9 
10 <p><> 转换为实体常用于防止浏览器将其用作 HTML 元素。当用户有权在您的页面上显示输入时,对于防止代码运行非常有用。</p>
11 
12 </body>
13 </html>

结果:

This is some <b>bold</b> text.

把 <> 转换为实体常用于防止浏览器将其用作 HTML 元素。当用户有权在您的页面上显示输入时,对于防止代码运行非常有用。

 

posted @ 2017-07-31 15:01  万里冰封  阅读(3395)  评论(0编辑  收藏  举报