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 내가 원하는 것은 2 html, em 및 strong을 활성화하는 것입니다. 이것은 xss에서 안전합니까? 만약에 우리가 그것을 어떻게 확보 할 수 있겠습니까?안전한 HTML PHP로 필터링?
많은 작업이 있습니다. 감사합니다 친구 –
@ 아담, @ jasonbar의 대답도 고려하시기 바랍니다. 'strip_tags'보다 [우수한 필터링 옵션] (http://htmlpurifier.org/comparison#striptags)을 제공합니다. – Charles