开发者

How to filter ads images when use `simple html dom` get site's images

I want use simple_html_dom to get some site's images. this is a test site. when I use some basic code below, I can get all开发者_如何转开发 the images. but how to filter ads images?

<?php
header('Content-type:text/html; charset=utf-8');
require_once 'simple_html_dom.php';
$v = 'http://www.vimeo.com/';
$html = file_get_html($v);
foreach($html->find('img') as $element) {
            $image = $element->src;
            echo '<img src="'.$image.'" /><hr />';
        }
?>

I notice some ads also as a jpg image format, but the url contains ad or ads, or something just as a gif image format... how to write some code to filter ads? thanks.


Search in your src if it find the ad(s) string. But that be too mush posibility, like admin,address,reading...

if (!preg_match("ads?", $element->src)) {
    //it's not an ad
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜