2012-05-14 36 views
0

我搶使用HTML DOM,當IM抓住一些圖像是SRC公司這樣表示其他網頁內容 -如何使用html DOM重新創建圖像src鏈接?

<img src="/datas/vt/data=Ay5GWBeob_WIPLDYoIWcfVXxvZu9XwJ55OX7Ag,OfrBKR" style="margin-right: 12px; margin-top: 1px; padding: 1px;" width="270" border="1" height="185"> 

有沒有什麼辦法內容添加到圖片src?例如:www.contentgrabbingsitename.com !!!

<img src="www.contentgrabbingsitename.com/datas/vt/data=Ay5GWBeob_WIPLDYoIWcfVXxvZu9XwJ55OX7Ag,OfrBKR" style="margin-right: 12px; margin-top: 1px; padding: 1px;" width="270" border="1" height="185"> 

我的代碼:

foreach($html->find('img') as $e) 
    echo $e->outertext . '<br>'; 
+0

您使用哪個庫來處理HTML DOM? –

+0

simple_html_dom.php !! –

+0

http://sourceforge.net/projects/simplehtmldom/ –

回答

1

您可以編輯的屬性,例如:

foreach($html->find('img') as $e) { 
    // prefix 'hello' to the src attribute 
    if ('/' == $e->src[0]) { 
     $e->src = "http://mydomain.com" . $e->src; 
    } 
} 

之後,你只需要保存網頁。

+0

該代碼將前綴hello添加到頁面上的每個圖像src!我只是想添加這個前綴到scr像這樣的圖像 - scr =「/ datas/vt/ –

+2

你從來沒有聽說過if語句嗎?;-) –

+0

是的,我做了一個代碼我自己與if和ur代碼和它的作品!!!! yehh !!感謝朋友.... –

相關問題