<?php
class Crawler
{
protected $markup = "";
public function __construct($url)
{
$this->markup = $this->getMarkup($url);
}
public function getMarkup($url)
{
return file_get_contents($url);
}
public function get($type)
{
$method = "_get_{$type}";
if (method_exists($this, $method))
{
return call_user_func(array($this, $method));
}
}
///For Img tag
protected function _get_images()
{
if (!empty($this->markup))
{
preg_match_all('/<img [^>]*src="http:?([^ ">]+)"?/i', $this->markup, $images);
return !empty($images[1]) ? $images[1] : FALSE;
}
}
///For Anchor tag
protected function _get_links()
{
if (!empty($this->markup))
{
preg_match_all('/
return !empty($links[1]) ? $links[1] : FALSE;
}
}
} // End of Crawler class
$url="http://500px.com/popular";
if(substr($url, 0, 4) != 'http') $url = 'http://'.$url;
$crawl = new Crawler($url);
$images = $crawl->get('images');
$links = $crawl->get('links');
$i = 0;
if(!empty($images)){
foreach($images as $img){
if($img[0] == "'") $img = substr($img,1,-1);
echo "<img src='".$img."'>";
$i++;
}
}
?>