我有一个表结构,我试图在插入查询之前从 moviedb.org 获取 movie_id。
这是代码的一部分
$movie_name = $arrTitle[0];
$apiKey = '30f44b6ef9472d414e50d2acaa058b60';
$url = simplexml_load_file("http://api.themoviedb.org/2.1/Movie.search/en/xml/30f44b6ef9472d414e50d2acaa058b60/"$movie_name"");
$xml = simplexml_load_file($url);
$movies = $xml->movies->movie;
$images = $xml->xpath("//image");
foreach ($movies as $movie){
$arrMovie_id = $movie->id;
}
foreach ($images as $image){
$attr = $image->attributes();
if($image['size'] == "thumb" && $image['type']=="poster"){
$images= $image['url'];
}
}
$arrStr = explode(':',$htmlShowTime);
$release = substr($arrStr[3],0,strlen($arrStr[3])-8);
$director = substr($arrStr[5],0,strlen($arrStr[5])-11);
$sql_movie = "insert into jos_movie(movie_name,language,cast,movie_release,director,rating,rating_count,movie_ids,image)values('$movie_name','null','$cast','$release','$director',250,230,'$arrMovie_id','$images')";
//echo $sql.'<br>';
// echo $sql_movie;
mysql_query($sql_movie);
如您所见,我试图从中获取 movie_id$url
但在图像字段中获取 0 和某些情况下的“Array”
例如第一部电影“Go Goa Gone”
网址是http://api.themoviedb.org/2.1/Movie.search/en/xml/30f44b6ef9472d414e50d2acaa058b60/%22Go%20Goa%20Gone%22
它应该获取 id 和 image
<?xml version="1.0" encoding="UTF-8"?>
<OpenSearchDescription xmlns:opensearch="http://a9.com/-/spec/opensearch/1.1/">
<opensearch:Query searchTerms=""Go+Goa+Gone""/>
<opensearch:totalResults>1</opensearch:totalResults>
<movies>
<movie>
<score>42.34326</score>
<popularity>3</popularity>
<translated>true</translated>
<adult>false</adult>
<language>en</language>
<original_name>Go Goa Gone</original_name>
<name>Go Goa Gone</name>
<alternative_name></alternative_name>
<type>movie</type>
<id>191562</id>
<imdb_id>tt2436516</imdb_id>
<url>http://www.themoviedb.org/movie/191562</url>
<votes>0</votes>
<rating>0.0</rating>
<certification>NR</certification>
<overview>A rave party off the coast of Goa, goes horrifyingly and hilariously wrong when the island is overrun with zombies.</overview>
<released>2013-05-10</released>
<images>
<image type="poster" url="http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w92/cSDvyWmh7rSD7WtSoXScVw3GDnD.jpg" size="thumb" width="92" height="133" id="51880dd7760ee3144531d0b9"/>
<image type="poster" url="http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w154/cSDvyWmh7rSD7WtSoXScVw3GDnD.jpg" size="w154" width="154" height="222" id="51880dd7760ee3144531d0b9"/>
<image type="poster" url="http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w185/cSDvyWmh7rSD7WtSoXScVw3GDnD.jpg" size="cover" width="185" height="267" id="51880dd7760ee3144531d0b9"/>
<image type="poster" url="http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w342/cSDvyWmh7rSD7WtSoXScVw3GDnD.jpg" size="w342" width="342" height="493" id="51880dd7760ee3144531d0b9"/>
<image type="poster" url="http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w500/cSDvyWmh7rSD7WtSoXScVw3GDnD.jpg" size="mid" width="500" height="721" id="51880dd7760ee3144531d0b9"/>
<image type="poster" url="http://d3gtl9l2a4fn1j.cloudfront.net/t/p/original/cSDvyWmh7rSD7WtSoXScVw3GDnD.jpg" size="original" width="810" height="1168" id="51880dd7760ee3144531d0b9"/>
<image type="backdrop" url="http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w300/mjxJT7skpStIGyp1bAe7XCsTVEN.jpg" size="thumb" width="300" height="169" id="51880e1f760ee3059e36a012"/>
<image type="backdrop" url="http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w780/mjxJT7skpStIGyp1bAe7XCsTVEN.jpg" size="poster" width="780" height="439" id="51880e1f760ee3059e36a012"/>
<image type="backdrop" url="http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w1280/mjxJT7skpStIGyp1bAe7XCsTVEN.jpg" size="w1280" width="1280" height="720" id="51880e1f760ee3059e36a012"/>
<image type="backdrop" url="http://d3gtl9l2a4fn1j.cloudfront.net/t/p/original/mjxJT7skpStIGyp1bAe7XCsTVEN.jpg" size="original" width="1280" height="720" id="51880e1f760ee3059e36a012"/>
</images>
<version>1</version>
<last_modified_at>2013-05-06 20:14:04 UTC</last_modified_at>
</movie>
</movies>
</OpenSearchDescription>
这是 var_dump 的$movie_name
string(12) "Go Goa Gone "
string(6) "Gippi "
string(19) "Shootout at Wadala "
string(23) "Lucky Di Unlucky Story "
string(11) "Aashiqui 2 "
对于这种不规则性,我在代码中哪里错了?