NicoJuicy
asked on
SimpleXML error on check if element exists
I have the below code in my script.
Is there anyway to change the "if element exists"? or the get_file_contents?
Sometimes this scripts works (one by one) and sometimes it doesn't....
(Warning: file_get_contents(http://www.trynt.com/movie-imdb-api/v2/?t=Ali+G-In+Da+House&fo=xml&f=0) [function.file-get-content s]: failed to open stream: HTTP request failed! in C:\xampp\htdocs\ListFilms\ includes\f unctions.p hp on line 33)
I have used the 2 different if statements, but both could give an error.
The first one is
if($xmlObj->{'movie-imdb'} ->{'matche d-url'} )
And the second one is
if(count($xmlObj->{'movie- imdb'}->{' matched-ur l'}) > 0)
The second possibilty is, that the error is fully dedicated to the file_get_contents
I want a solution to solve this problem.
Is there anyway to change the "if element exists"? or the get_file_contents?
Sometimes this scripts works (one by one) and sometimes it doesn't....
(Warning: file_get_contents(http://www.trynt.com/movie-imdb-api/v2/?t=Ali+G-In+Da+House&fo=xml&f=0) [function.file-get-content
I have used the 2 different if statements, but both could give an error.
The first one is
if($xmlObj->{'movie-imdb'}
And the second one is
if(count($xmlObj->{'movie-
The second possibilty is, that the error is fully dedicated to the file_get_contents
I want a solution to solve this problem.
function updateDB($connection)
{
$sql ="SELECT * FROM films WHERE imdbUrl = '' OR imdbUrl = 'no'";
if (!($temp = mysql_query($sql,$connection)))
showerror();
while ($films = mysql_fetch_array($temp))
{
echo $films['titel'];
//get contents of de xml pagina
$stringXML = file_get_contents("http://www.trynt.com/movie-imdb-api/v2/?t=" .str_ireplace(" ","+",$films['titel']) . "&fo=xml&f=0");
$xmlObj = new SimpleXMLElement($stringXML); //doorzoek de xmlpagina
//voorgaand : if($xmlObj->{'movie-imdb'}->{'matched-url'} )
if(count($xmlObj->{'movie-imdb'}->{'matched-url'}) > 0)
{
$imdbUrl= $xmlObj->{'movie-imdb'}->{'matched-url'}; //exacte Url van imdb link
}else{
$imdbUrl = "no";
}
echo "<i>" . $imdbUrl . "</i>";
$sql2 = "UPDATE films SET imdbUrl = '" . $imdbUrl . "' WHERE id = '" . $films['id'] . "'";
echo $sql2;
mysql_query($sql2);
usleep(50);
}
}
The error on file_get_contents() means it could not find the file it was meant to open.
Put these two lines in to make sure you are parsing the file name and path correctly.
Put these two lines in to make sure you are parsing the file name and path correctly.
$file_name = "http://www.trynt.com/movie-imdb-api/v2/?t=" .str_ireplace(" ", "+", $films['titel']) . "&fo=xml&f=0";
echo "the file name is : $file_name";
ASKER
The url is always correct.. :(
Are you sure this is right?
if ($xmlObj->{'movie-imdb'}-> {'matched- url'})
I thought it would be
if ($xmlObj->movie-imdb->matc hed-url)
if ($xmlObj->{'movie-imdb'}->
I thought it would be
if ($xmlObj->movie-imdb->matc
ASKER
Yes i am,
because simplexml doesn't support other chars (eg. - )
when there is - in an element, you have to do this with {'element-name')
because ->element-name
wont work :)
because simplexml doesn't support other chars (eg. - )
when there is - in an element, you have to do this with {'element-name')
because ->element-name
wont work :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
The second query always fails on the file_get_contents() ...
Can anyone help me out? :)