Your IP : 216.73.216.40


Current Path : /var/www/html/mmishra/indem/wisdom.bak/
Upload File :
Current File : /var/www/html/mmishra/indem/wisdom.bak/webcrawler.php

<?php
class Crawler {
  
  	protected $markup = '';
  
  	public function __construct($uri) {
    		$this->markup = $this->getMarkup($uri);  
  	}
  
  	public function getMarkup($uri) {
    		return file_get_contents($uri);   
  	}

  	public function get($type) {
    		$method = "_get_{$type}";
    		if (method_exists($this, $method)){
      			//return call_user_method($method, $this);
      			return call_user_func($method, $this);
    		}
  	}
  
  	protected function _get_images() {
    		if (!empty($this->markup)){
      			preg_match_all('/<img([^>]+)\/>/i', $this->markup, $images);         
      			return !empty($images[1]) ? $images[1] : FALSE;
    		}
  	}
  
  	protected function _get_links() {
    		if (!empty($this->markup)){
      			preg_match_all('/<a([^>]+)\>(.*?)\<\/a\>/i', $this->markup, $links);  
      			return !empty($links[1]) ? $links[1] : FALSE;
    		}
  	}
}

$crawl = new Crawler('http://www.iiita.ac.in/');
$images = $crawl->get('images');
$links = $crawl->get('links');
echo $images;
echo "\n";
echo $links;
echo "\n";
?>