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
}
精彩评论