Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我在网站中有一些用户输入,以后用 PHP 输出该输入时我不想允许 HTML 。
我认为唯一危险的字符是<, >, /(slash) 和\(backslash)。
<
>
/
\
我对吗?
因此,例如,如果我替换<为<是否足以防止 HTML 被输出?
<
只需使用内置函数htmlspecialchars(),你就会很好。请注意,您还应该始终添加编码参数。
htmlspecialchars()
例如:
echo htmlspecialchars($unsafeString, ENT_QUOTES, 'UTF-8');