i am trying to check through php if xml files exists on a url (incremental names till it fails)
why is this code not working?
<?php
for ($i = 1; $i <= 10; $i++) {
$url = "http://thetvdb.com/api/E676DF9578EF38D7/series/78901/default/".$i."/1/en.xml";
echo $url."<br />";
$xml = simplexml_load_file($url);
if ($xml) {
echo "yay"."<br />";
} else {
echo "fail"."<br />";
die();
}
}
?>
Your main problem is
die(). This quits all execution.I’d also try using
fopen()instead ofsimplexml_load_file()unless you plan on using the XML later on, eg