2013-04-11 59 views
0

好的。我從IMDb上下了一張海報,對於我的生活,我無法弄清楚它爲什麼不顯示 - 我只是得到一個像圖像丟失的小問號。這是我當前的代碼:使用Simple_HTML_DOM不顯示刮痕圖像

<?php  
$p = 1; 
foreach($movie_html->find("div[class=image]") as $poster1) 
{ 
    foreach($poster1->find("img") as $poster2) 
    { 
     $p++; 
     if ($p == 1) break; 
    } 
} 
$poster3 = $poster2->src; 
?> 

<img src="<?php echo($poster3); ?>" height="300"/> 

當我只是echo$poster3變量返回的圖像(所以我知道代碼工作像它應該),但在實際的網頁,我不」的正確網址看不到圖像。相反,我得到的只是一個小問號,就好像圖像不在指定的URL一樣。當我右鍵單擊該框並強制Safari在新選項卡中打開圖像時,我看到圖像恰好坐在那裏,非常漂亮!但由於某種原因,它不會顯示在我的網站上。

任何想法? IMDb是否將我鎖定以防止刮板?或者我的代碼中有東西嗎?

回答

0

這是如何工作的?

<?php 
/* getIMDB.php 
    -- displays movie poster (and its url as a tool-tip) from an IMDB page 
*/ 
    include_once('../simpleHTML/simple_html_dom.php'); 

    $url = "http://www.imdb.com/title/tt0246578/"; 
    $movie_html = file_get_html($url); 
    outputImg($movie_html); 


function outputImg($movie_html) 
{ 
    $p = 1; 
    foreach($movie_html->find("div[class=image]") as $poster1) 
    { 
     foreach($poster1->find("img") as $poster2) 
     { 
      $p++; 
      if ($p == 1) break; 
     } 
    } 
    $poster3 = $poster2->src; 
    echo "<img src='" . $poster3 . "' title='" . $poster3 . "'/>"; 
} 
?>