2012-02-05 82 views
0

我想獲得一個名爲div的內容:<img id="hplogo-img" src="thelinkiwant"/>的preg_match獲得DIV內容

我有這個代碼不工作,它只是呼應的「數組」:

<?php 
include_once('simple_html_dom.php'); 
$html = file_get_html($url); 
preg_match('/<img id= \'hplogo-img\'>(.*)<\/div>/s',$html,$matches); 
echo $matches; 
?> 

如果有可能用直接PHP來做到這一點,這將是首選。任何想法,爲什麼我不能從div的鏈接?

回答

2

爲什麼不使用解析器提供的方法。

$ret = $html->find('img[id=hplogo-img]'); 
2

$ matches是一個數組。

使用

print_r($matches) 

您應該看到陣列內容:)

的第一要素應該是你要尋找的嘗試。所以製作:

echo $matches[0];