Checking multiple XML in PHP I am working on a code to see if a video already exists. The problem is that I have to check multiple sections. The code is working but it should not be this big, I think, and it takes a long time to load.

Is there an easier way to do this?

$xmlurl7b = 'http://mysite.me/library/sections/2/all?title=' . $movie-&gt;title() . '&amp;HndJk7Sd'; 
$xmlurl1b = 'http://mysite.me/library/sections/5/all?title=' . $movie-&gt;title() . '&amp;HndJk7Sd'; 
$xmlurl2b = 'http://mysite.me/library/sections/7/all?title=' . $movie-&gt;title() . '&amp;HndJk7Sd'; 
$xmlurl3b = 'http://mysite.me/library/sections/9/all?title=' . $movie-&gt;title() . '&amp;HndJk7Sd'; 
$xmlurl4b = 'http://mysite.me/library/sections/10/all?title=' . $movie-&gt;title() . '&amp;HndJk7Sd'; 
$xmlurl5b = 'http://mysite.me/library/sections/11/all?title=' . $movie-&gt;title() . '&amp;HndJk7Sd'; 
$xmlurl6b = 'http://mysite.me/library/sections/13/all?title=' . $movie-&gt;title() . '&amp;HndJk7Sd'; 
$xmlurl8 = 'http://mysite.me/library/sections/3/all?title=' . $movie-&gt;title() . '&amp;HndJk7Sd'; 
$xmlurl9 = 'http://mysite.me/library/sections/8/all?title=' . $movie-&gt;title() . '&amp;HndJk7Sd';
$xmlurl7 = 'http://mysite.me/library/sections/2/all?guid=movieid' . $movieid . '%3Flang%3Dnl&amp;HndJk7Sd';
$xmlurl1 = 'http://mysite.me/library/sections/5/all?guid=movieid' . $movieid . '%3Flang%3Dnl&amp;HndJk7Sd';
$xmlurl2 = 'http://mysite.me/library/sections/7/all?guid=movieid' . $movieid . '%3Flang%3Dnl&amp;HndJk7Sd';
$xmlurl3 = 'http://mysite.me/library/sections/9/all?guid=movieid' . $movieid . '%3Flang%3Dnl&amp;HndJk7Sd';
$xmlurl4 = 'http://mysite.me/library/sections/10/all?guid=movieid' . $movieid . '%3Flang%3Dnl&amp;HndJk7Sd';
$xmlurl5 = 'http://mysite.me/library/sections/11/all?guid=movieid' . $movieid . '%3Flang%3Dnl&amp;HndJk7Sd';
$xmlurl6 = 'http://mysite.me/library/sections/13/all?guid=movieid' . $movieid . '%3Flang%3Dnl&amp;HndJk7Sd';
$achxml8 = simplexml_load_file($xmlurl8);
$achxml9 = simplexml_load_file($xmlurl9);
$achxml1 = simplexml_load_file($xmlurl1);
$achxml2 = simplexml_load_file($xmlurl2);
$achxml3 = simplexml_load_file($xmlurl3);
$achxml4 = simplexml_load_file($xmlurl4);
$achxml5 = simplexml_load_file($xmlurl5);
$achxml6 = simplexml_load_file($xmlurl6);
$achxml7 = simplexml_load_file($xmlurl7);
$achxml1b = simplexml_load_file($xmlurl1b);
$achxml2b = simplexml_load_file($xmlurl2b);
$achxml3b = simplexml_load_file($xmlurl3b);
$achxml4b = simplexml_load_file($xmlurl4b);
$achxml5b = simplexml_load_file($xmlurl5b);
$achxml6b = simplexml_load_file($xmlurl6b);
$achxml7b = simplexml_load_file($xmlurl7b);
if( $achxml1-&gt;Video &amp;&amp; ($achxml1-&gt;Video != '') 
OR $achxml2-&gt;Video &amp;&amp; ($achxml2-&gt;Video != '') 
OR $achxml3-&gt;Video &amp;&amp; ($achxml3-&gt;Video != '') 
OR $achxml4-&gt;Video &amp;&amp; ($achxml4-&gt;Video != '') 
OR $achxml5-&gt;Video &amp;&amp; ($achxml5-&gt;Video != '') 
OR $achxml6-&gt;Video &amp;&amp; ($achxml6-&gt;Video != '') 
OR $achxml7-&gt;Video &amp;&amp; ($achxml7-&gt;Video != '')
OR $achxml8-&gt;Directory &amp;&amp; ($achxml8-&gt;Directory != '')
OR $achxml9-&gt;Directory &amp;&amp; ($achxml9-&gt;Directory != '')
OR $achxml1b-&gt;Video &amp;&amp; ($achxml1b-&gt;Video != '') 
OR $achxml2b-&gt;Video &amp;&amp; ($achxml2b-&gt;Video != '') 
OR $achxml3b-&gt;Video &amp;&amp; ($achxml3b-&gt;Video != '') 
OR $achxml4b-&gt;Video &amp;&amp; ($achxml4b-&gt;Video != '') 
OR $achxml5b-&gt;Video &amp;&amp; ($achxml5b-&gt;Video != '') 
OR $achxml6b-&gt;Video &amp;&amp; ($achxml6b-&gt;Video != '') 
OR $achxml7b-&gt;Video &amp;&amp; ($achxml7b-&gt;Video != '')
 ) {
echo 'Exists';
} else {
echo 'New'; 
}
This is a giant mess! Here's what you should do to start cleaning it up. 

Code organization


Everything you are doing is quite repetitive with minimal variations. Start by constructing an array of each section number you need to inspect for title and each section number you need to inspect by guid. You can then iterate through these systematically without writing everything out.
Turn these two strings into constants you define at the top of your file '%3Flang%3Dnl&amp;HndJk7Sd'  and '&amp;HndJk7Sd'. SImilarly does $movie->title() return the same value each time you call it? If so, move this value into a constant too. 
I would then do a loop of a kind like this (pseudocode):

for each filename in possible files{
 video = simplexml_load_file(filename)
 if(video-&gt;Video &amp;&amp; video-&gt;Video!='') {
     echo 'Exists'
     gracefully exit script?
}
//If script has not exited file doesn't exist
echo 'New';

Note that this general organization means you stop as soon as you find a file. The way you have set up your code now, you load all directories but you might have actually found the video in the very first place you checked. 


PHP language features


Any reason the standard function file_exists() isn't applicable in some way? Not sure why you seem to have all these special functions just to check if a file exists?