0

我想simple_html_dom用来获取一些网站的图像。这是一个测试站点。当我使用下面的一些基本代码时,我可以获得所有图像。但是如何过滤广告图片?

<?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 />';
        }
?>

我注意到一些广告也是jpg image format,但 url 包含ador ads,或者只是gif image format...如何编写一些代码来过滤广告?谢谢。

4

1 回答 1

0

如果找到广告字符串,请在您的 src 中搜索。但这太糊涂了,比如admin,,address...reading

if (!preg_match("ads?", $element->src)) {
    //it's not an ad
}
于 2011-04-13T09:19:13.117 回答