function validCleanHtml($unclosedString)
{
preg_match_all("/<([^\/]\w*)>/", $closedString = $unclosedString, $tags);
for ($i = count($tags[1]) - 1; $i >= 0; $i--)
{
$tag = $tags[1][$i];
if (substr_count($closedString, "</$tag>") < substr_count($closedString, "<$tag>"))
$closedString .= "</$tag>";
}
$validTags = "<em><strong>";
$validClosedString = strip_tags($closedString, $validTags);
return $validClosedString;
}
ok ce que je veux est d'activer 2 html, em et fort, est-ce juste sécurisé de xss? sinon comment pouvons-nous le sécuriser?filtrage html sûr avec php?
C'est beaucoup de travail. merci compagnon –
@Adam, s'il vous plaît considérer la réponse de @ jasonbar aussi bien. Il fournit [options de filtrage supérieures] (http://htmlpurifier.org/comparison#striptags) que 'strip_tags'. – Charles