PHP上允许的标记列表';s strip_标签()
这是一个如何使用函数的典型示例PHP上允许的标记列表';s strip_标签(),php,function,strip-tags,Php,Function,Strip Tags,这是一个如何使用函数的典型示例 <h1><?php echo htmlentities($post->title); ?></h1> // post content here <?php echo strip_tags($post->content); ?> //在这里发布内容 因此,我创建了一个别名函数来剥离标记,如下所示: function strip($var) { $allowed = '<div&
<h1><?php echo htmlentities($post->title); ?></h1>
// post content here
<?php echo strip_tags($post->content); ?>
//在这里发布内容
因此,我创建了一个别名函数来剥离标记,如下所示:
function strip($var) {
$allowed = '<div><span><pre><p><br><hr><hgroup><h1><h2><h3><h4><h5><h6>
<ul><ol><li><dl><dt><dd><strong><em><b><i><u>
<img><a><abbr><address><blockquote><area><audio><video>
<form><fieldset><label><input><textarea>
<caption><table><tbody><td><tfoot><th><thead><tr>
<iframe>';
return strip_tags($var, $allowed);
}
功能条($var){
$allowed='
-
';
返回条带标签($var,$allowed);
}
用这个代替:
//在这里发布内容
我的问题是我需要在$allowed数组中添加更多标记,还是删除一些?
在阵列上添加哪些其他标记被认为是“无害的”?如果您担心攻击,而不是
更新了链接并且非常温和,您可以添加它们。即使是
也可以用作邪恶
@dwhite.me“邪恶”的意思是标记,例如,这就是为什么我去掉它们。@technol您可能是对的,我想做的是列出一个标签列表,这些标签在诸如POST之类的情况下可以起到较少或没有伤害的作用。如果我们更深入地研究安全问题,那么最好的建议是使用htmlentities()
或htmlspecialchars()
链接无效。@yuri1000更新了链接
<h1><?php echo htmlentities($post->title); ?></h1>
// post content here
<?php echo strip($post->content); ?>