SimpleXML Undefined Variable
Posted: Fri Jun 04, 2010 4:29 am
Hi
I am just beggining to learn PHP and am trying to use it to parse and XML document i am accessing, the xml document is:
Now i have been following a few tutorials and they all seem to suggest the same thing but no matter what i have tried i get the following error:
and here is the code I am using:
I am running PHP 5 and thought that SimpleXML was bundled with it but it just aint working for me, any help would be appreciated.
Thanks in advance!
I am just beggining to learn PHP and am trying to use it to parse and XML document i am accessing, the xml document is:
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
<opensearch:Query searchTerms="Transformers"/>
<opensearch:totalResults>8</opensearch:totalResults>
<movies>
<movie>
<score>9</score>
<popularity>3</popularity>
<translated>true</translated>
<language>en</language>
<name>Transformers: Revenge of the Fallen</name>
<alternative_name>Transformers 2</alternative_name>
<type>movie</type>
<id>8373</id>
<imdb_id>tt1055369</imdb_id>
<url>http://www.themoviedb.org/movie/8373</url>
<rating>6.2</rating>
<certification>PG-13</certification>
<overview>Decepticon forces return to Earth on a mission to take Sam Witwicky prisoner, after the young hero learns the truth about the ancient origins of the Transformers. Joining the mission to protect humankind is Optimus Prime, who forms an alliance with international armies for a second epic battle.</overview>
<released>2009-06-24</released>
<images>
<image type="poster" url="http://i1.themoviedb.org/posters/387/4bc92151017a3c57fe00d387/transformers-revenge-of-the-fallen-original.jpg" size="original" width="1080" height="1602" id="4bc92151017a3c57fe00d387"/>
<image type="poster" url="http://i2.themoviedb.org/posters/387/4bc92151017a3c57fe00d387/transformers-revenge-of-the-fallen-mid.jpg" size="mid" width="500" height="742" id="4bc92151017a3c57fe00d387"/>
<image type="poster" url="http://i3.themoviedb.org/posters/387/4bc92151017a3c57fe00d387/transformers-revenge-of-the-fallen-cover.jpg" size="cover" width="185" height="275" id="4bc92151017a3c57fe00d387"/>
<image type="poster" url="http://i2.themoviedb.org/posters/387/4bc92151017a3c57fe00d387/transformers-revenge-of-the-fallen-thumb.jpg" size="thumb" width="92" height="137" id="4bc92151017a3c57fe00d387"/>
<image type="backdrop" url="http://i3.themoviedb.org/backdrops/350/4bc92149017a3c57fe00d350/transformers-revenge-of-the-fallen-original.jpg" size="original" width="1920" height="1080" id="4bc92149017a3c57fe00d350"/>
<image type="backdrop" url="http://i2.themoviedb.org/backdrops/350/4bc92149017a3c57fe00d350/transformers-revenge-of-the-fallen-poster.jpg" size="poster" width="780" height="439" id="4bc92149017a3c57fe00d350"/>
<image type="backdrop" url="http://i3.themoviedb.org/backdrops/350/4bc92149017a3c57fe00d350/transformers-revenge-of-the-fallen-thumb.jpg" size="thumb" width="300" height="169" id="4bc92149017a3c57fe00d350"/>
</images>
<last_modified_at>2010-06-02 01:34:57</last_modified_at>
</movie>
</movies>
</OpenSearchDescription>
Code: Select all
Notice: Undefined variable: OpenSearchDescription in D:\Apache\htdocs\MovieCatalogue\index.php on line 3
Code: Select all
<?php
$xml = simplexml_load_file('http://api.themoviedb.org/2.1/Movie.search/en/xml/.../Transformers');
$name = $OpenSearchDescription->movies->movie->name;
?>
<html xml:lang="en" lang="en">
<head>
<title><?php
// The title will be read from the RSS
echo $name;
?>
</title>
</head>
<body>
<h1>test</h1>
<?php
// Here we'll put a loop to include each item's title and description
?>
</body>
</html>
Thanks in advance!