2012-01-19 161 views
0

我有很大的內容。通過file_get_content獲取。它是這樣的:從內容中獲取圖片網址

<div class="nwsdetail"> 


    <div class="othernws"> 
     <div class="ttlcate"> 
      Các tin đã đăng</div> 
     <div class="items"> 

       <div class="nwsoitem"> 
        <img width="9px" src="pic/web/icon/blue_bullet.gif" border="0" /> <a class="nwsottl" href='?u=nws&su=d&cid=10&id=53948'> 
         Những con số thống kê Internet của năm 2010 và 2011 
        </a> 

        </div> 

        <div class="sepothernws"> 
        </div> 

       <div class="nwsoitem"> 
        <img width="9px" src="pic/web/icon/blue_bullet.gif" border="0" /> <a class="nwsottl" href='?u=nws&su=d&cid=10&id=53946'> 
         Ít giám đốc tiếp thị biết khai thác sức mạnh thông tin số 
        </a> 
        </div> 

        <div class="sepothernws"> 

        </div> 

       <div class="nwsoitem"> 
        <img width="9px" src="pic/web/icon/blue_bullet.gif" border="0" /> <a class="nwsottl" href='?u=nws&su=d&cid=10&id=53943'> 
         Dùng gói SMS nội mạng MobiFone, nhận khuyến mại tiền tỷ 
        </a> 
        </div> 

        <div class="sepothernws"> 
        </div> 

       <div class="nwsoitem"> 

        <img width="9px" src="pic/web/icon/blue_bullet.gif" border="0" /> <a class="nwsottl" href='?u=nws&su=d&cid=10&id=53936'> 
         CIO đầu tiên của Chính phủ Mỹ gia nhập Salesforce 
        </a> 
        </div> 

        <div class="sepothernws"> 
        </div> 

       <div class="nwsoitem"> 
        <img width="9px" src="pic/web/icon/blue_bullet.gif" border="0" /> <a class="nwsottl" href='?u=nws&su=d&cid=10&id=53934'> 

         Symantec thâu tóm LiveOffice 
        </a> 
        </div> 

     </div> 
    </div> 
</div> 

在這個內容有一些圖片的URL,現在我希望把所有圖片的URL從這個內容到陣列圖像URL

請指導我。非常感謝你。

回答

1

您可以使用preg_match_all來過濾內容並創建一個包含所有img標籤的src值的數組。

$input = "your html from file_get_contents"; 
preg_match_all('/<img[^>]+>/i',$input, $result); 

$images = array(); 
foreach($result as $image) 
{ 
    preg_match_all('/src=("[^"]*")/i',$image, $images[$img_tag]); 
} 
+0

please cleaner $ img_tag – vinanghinguyen 2012-01-19 01:24:29

1

結賬simple HTML DOM。有了它,你可以從頁面上抓取任何東西。