Html validation function in php:
And best way to use this:
function isValidHtml($string) {
$string = "<div>".$string."</div>"; $start = strpos($string, '<'); $end = strrpos($string, '>', $start); if($start === false && $end === false) { return true; } if ($end !== false) { $string = substr($string, $start); } else { $string = substr($string, $start, $end - $start); } libxml_use_internal_errors(true); libxml_clear_errors(); $xml = simplexml_load_string($string); return count(libxml_get_errors()) == 0; }
if(isValidHtml($strHtml) { echo "Valid html"; }
$strHtml = "<table><tr><td>Hi pritom</td></tr><table>"; is FALSE
No comments:
Post a Comment