从内容中获取图片网址

问题描述:

I have big content. get by file_get_content. It like this:

<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>

In this content have some images url and now I want put all images url from this content into array image url

please guide me. thanks you very much.

You can use preg_match_all to filter through the content and create an array that contains all of the img tag's src values.

$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]);
}

Check out simple HTML DOM. With it, you can grab just about anything from a page.