我正在接受用户的输入,我想禁止一些html标签,比如,还想禁止onclick、onmousemove、onmouseover等属性
此外,用户仍然可以编写类似htmlphpjQuery的编程语言代码进行讨论。但它不应该运行
请引导我
这里有一个我使用过的函数,您可以根据自己的需要进行定制。
function strip_unsafe($string, $img=false)
{
// Unsafe HTML tags that members may abuse
$unsafe=array(
'/<iframe(.*?)</iframe>/is',
'/<title(.*?)</title>/is',
'/<pre(.*?)</pre>/is',
'/<frame(.*?)</frame>/is',
'/<frameset(.*?)</frameset>/is',
'/<object(.*?)</object>/is',
'/<script(.*?)</script>/is',
'/<embed(.*?)</embed>/is',
'/<applet(.*?)</applet>/is',
'/<meta(.*?)>/is',
'/<!doctype(.*?)>/is',
'/<link(.*?)>/is',
'/<body(.*?)>/is',
'/</body>/is',
'/<head(.*?)>/is',
'/</head>/is',
'/onload="(.*?)"/is',
'/onunload="(.*?)"/is',
'/<html(.*?)>/is',
'/</html>/is');
// Remove graphic too if the user wants
if ($img==true)
{
$unsafe[]='/<img(.*?)>/is';
}
// Remove these tags and all parameters within them
$string=preg_replace($unsafe, "", $string);
return $string;
}