I have
foreach($users as $user){
$doc = new DOMDocument();
$doc->loadXml(file_get_contents($user["syncUrl"]));
}
if the content in the url on $user[“syncUrl”], does so the loadXml() returns error (if it cant read), i would like it to just continue; and dont read the rest in the loop, until next loop (next $user).
Right now it is crashing, and outputs that it cant read because of wrong format. But i would like it to just jump over this and continue with the rest then.
How can i do this?
Hehe, you have it in your question:
continue;is the command to skip the rest of the loop and start the next iteration. Do error checking on $doc->loadXML and if it doesn’t successfully load, thencontinue;.So:
Might also be wise to use
DOMDocument::validate()to validate the format (from the DTD) andcontinueif not valid. You can also useDOMDocument::schemaValidateSource()to provide a source schema and useDOMDocument::schemaValidate()to validate the format from that schema. You can also do this to have it validated on load:Which would probably be necessary to have the loading function return false if the file stuff is actually there.