PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?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>
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:
<?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>
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.
<?php
$xml = simplexml_load_file('http://api.themoviedb.org/2.1/Movie.search/en/xml/.../Transformers');
$name = $xml->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<?php // The title will be read from the RSS again ?></h1>
<?php
// Here we'll put a loop to include each item's title and description
?>
</body>
</html>
Like I said before, you don't reference the document-root; your $xml variable already does this. Your document-root is the root element of your XML (OpenSearhDescription).
<?php
$xml = simplexml_load_file('http://api.themoviedb.org/2.1/Movie.search/en/xml/9301bee61d34d15ab5ef8f9934263112/Transformers');
$name = $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
<?php
// The title will be read from the RSS again
?>
</h1>
<?php
// Here we'll put a loop to include each item's title and description
?>
</body>
</html>
and this is the start of what the var_dump as suggested above gives out:
object(SimpleXMLElement)#1 (1) {
["movies"]=>
object(SimpleXMLElement)#2 (1) {
["movie"]=>
array(8) {
[0]=>
object(SimpleXMLElement)#3 (16) {
["score"]=>
string(1) "9"
["popularity"]=>
string(1) "3"
["translated"]=>
string(4) "true"
["language"]=>
string(2) "en"
["name"]=>
string(35) "Transformers: Revenge of the Fallen"
["alternative_name"]=>
string(14) "Transformers 2"
["type"]=>
string(5) "movie"
["id"]=>
string(4) "8373"
["imdb_id"]=>
string(9) "tt1055369"
["url"]=>
string(36) "http://www.themoviedb.org/movie/8373"
["rating"]=>
string(3) "6.2"
["certification"]=>
string(5) "PG-13"
["overview"]=>
string(295) "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."
["released"]=>
string(10) "2009-06-24"
["images"]=>
object(SimpleXMLElement)#11 (1) {
["image"]=>
array(7) {
[0]=>
object(SimpleXMLElement)#12 (1) {
["@attributes"]=>
array(6) {
["type"]=>
string(6) "poster"
["url"]=>
string(109) "http://i1.themoviedb.org/posters/387/4bc92151017a3c57fe00d387/transformers-revenge-of-the-fallen-original.jpg"
["size"]=>
string(8) "original"
["width"]=>
string(4) "1080"
["height"]=>
string(4) "1602"
["id"]=>
string(24) "4bc92151017a3c57fe00d387"
}
}
[1]=>
From the var dump it looks like this should be working shouldn't it?