2017-06-14 42 views
-3

AA親愛的兄弟得到IMG SRC從一個HTML頁面,我想從一個HTML頁面的屁股我都面臨着錯誤的IMG SRC,請幫助,我的服務器顯示此messaage我如何使用PHP

注意:未定義偏移量:0在F:\ xamppppp \ htdocs中\ Arslan_Sir \ IMG從google.php第13行聲明 下載:Array對F中字符串 轉換:\ xamppppp \ htdocs中\ Arslan_Sir \從 谷歌IMG下載.php 15行Array

我的代碼是

<?php //this code can be pic 
image from a html page $ctual_link="https://www.google.com/search?q=9780333993385&ie=utf-8&oe=utf-8&client=firefox-b-ab"; define('DIRECTORY', '/imgg/m/'); $text = file_get_contents($ctual_link); preg_match_all('/<div class=\"image\">(.*?)<\/div>/s', $text, $out); //preg_match('/~src="(.*)"itemprop="image" \/>/',$text,$out); preg_match('~src="(.*)"\s*itemprop="image"[^>]*>~',$text,$out); //$out 
= explode(' ',$out[1]); $z=trim($out[0],'"'); echo $out; //}  ?> 
+1

親愛的兄弟,請閱讀[問]然後相應地編輯你的問題。 – domsson

+2

[Notice:Undefined offset:0 in](https://stackoverflow.com/q/6549561/6521116)可能的副本 –

回答

0

不太清楚,但是從圖書館

$html = file_get_html('http://www.google.com/'); 

// Find all images 
foreach($html->find('img') as $element) 
     echo $element->src . '<br>'; 
0

解決您的問題的着陸頁想着PHP簡單的HTML DOM解析器

的例子,你可以使用這個代碼它會幫助你更好

<?php 
$ctual_link="https://www.google.com/search?q=9780333993385&ie=utf-8&oe=utf-8&client=firefox-b-ab"; 

$html = file_get_contents($ctual_link); 
//Create a new DOM document 
$dom = new DOMDocument; 

@$dom->loadHTML($html); 

$links = $dom->getElementsByTagName('img'); 

foreach ($links as $link){ 
    //Extract and show the "src" attribute of image. 
    echo $link->nodeValue; 
    echo $link->getAttribute('src'), '<br>'; 
} 
?>