如何使用 PHP 检查字符串是否是有效的 XHTML?
how to check if string is valid XHTML using PHP?
正在使用
$html = '<br /><p>k</p>';
libxml_use_internal_errors(true);
$dom = New DOMDocument();
$dom -> loadXML($correo_elhtml);
echo '<pre>';
if(empty(libxml_get_errors())){
echo "This is a good HTML";
}
else {
echo "This not html";
print_r(libxml_get_errors());
}
return 错误,但这是一个有效的 XHTML 字符串。
请问有什么功能吗?
此代码是正确的 HTML 但不正确 XML,因为空元素标记,例如 XML 中的 <br />
必须仅在 <section></section>
因此您可以使用 $dom -> loadHTML($html);
或从 HTML 中删除 <be />
,然后使用 $dom -> loadXML($html);
正在使用
$html = '<br /><p>k</p>';
libxml_use_internal_errors(true);
$dom = New DOMDocument();
$dom -> loadXML($correo_elhtml);
echo '<pre>';
if(empty(libxml_get_errors())){
echo "This is a good HTML";
}
else {
echo "This not html";
print_r(libxml_get_errors());
}
return 错误,但这是一个有效的 XHTML 字符串。
请问有什么功能吗?
此代码是正确的 HTML 但不正确 XML,因为空元素标记,例如 XML 中的 <br />
必须仅在 <section></section>
因此您可以使用 $dom -> loadHTML($html);
或从 HTML 中删除 <be />
,然后使用 $dom -> loadXML($html);