There is no such function, but you can rest assured that some $string
is well-formed XML when DOMDocument::loadXML()
returned true
(set recover to false). A HTML document fails with that.
For HTML you can use DOMDocument::loadHTML()
to check if a document can be loaded as HTML. HTML is not as strict as XML.
Use preg_match extension. Example:
if( preg_match('/<html[^>]*>/', $string) ) {
{
// ... actions for XML ...
} elseif( preg_match('/<\?xml[^?]*\?>/', $string) ) {
// ... actions for HTML ...
} else {
// ... actions for another ...
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.