htmlspecialchars、strip_tags和addslashes的區別

htmlspecialchars() 函數把一些預約義的字符轉換爲 HTML 實體。php

預約義的字符是:html

  • & (和號) 成爲 &函數

  • " (雙引號) 成爲 "code

  • ' (單引號) 成爲 'htm

  • < (小於) 成爲 &lt;ip

  • > (大於) 成爲 &gt;ci


addslashes() 函數在指定的預約義字符前添加反斜槓。字符串

這些預約義字符是:string

  • 單引號 (')table

  • 雙引號 (")

  • 反斜槓 (\)

  • NULL

<?php

$str = "Who's John Adams?";
echo $str . " This is not safe in a database query.<br />";
echo[object Object]de> . " This is safe in a database query.";
?>

Who's John Adams? This is not safe in a database query.
Who\'s John Adams? This is safe in a database query.




strip_tags() 函數剝去 HTML、XML 以及 PHP 的標籤。

即不帶任何的標記,轉換成字符串。

<?php
echo strip_tags("Hello <b><i>world!</i></b>",[object Object]de>);
?>
strip_tags(string,allow)
參數 描述
string 必需。規定要檢查的字符串。
allow 可選。規定容許的標籤。這些標籤不會被刪除
相關文章
相關標籤/搜索