Lets just code, create a file named Scrap.php code it like this.
class Scrap{
protected static $url = '';
public static function setUrl($url){
self::$url = $url;
}
//Check the url
public static function checkUrl(){
//valid url given...?
if (filter_var(self::$url, FILTER_VALIDATE_URL) === FALSE){
return false;
}else{
//cek the url status
$array = @get_headers(self::$url);
$status = $array[0];
if(strpos($status,"200") or strpos($status,"301")){
return true;
}
return false;
}
}
//getting meta tags
public static function getMeta($attr=null){
if($attr){
$meta = get_meta_tags(self::$url);
return isset($meta[$attr]) ? $meta[$attr] : 'No meta found';
}
return get_meta_tags(self::$url);
}
private static function explodeTitle($a,$b,$c){
$y = explode($b,$a);
$x = explode($c,$y[1]);
return $x[0];
}
//getting title
public static function getTitle(){
return scrap::explodeTitle(file_get_contents(self::$url),""," ");
} //get the Domain
public static function getDomain(){
$dmn = parse_url(self::$url);
return $dmn['host'];
}
//getting images with DOMdocument
public static function getImg(){
$html = file_get_contents(self::$url);
$doc = new DOMDocument;
@$doc->loadHTML($html);
$tags = $doc ->getElementsByTagName('img');
$arr = array();
foreach ($tags as $tag) {
$arr[] = $tag->getAttribute('src');
}
//return only the first image
if(!empty($arr))
return $arr[0];
return "http://codetrash/assets/images/sains.png";
}
}
Now, we call the Class inside index.php. So create a file named index.php and code it
include "scrap.php";
$url = "http://codetrash.com/category/php/79/accessing-controller-layout-inside-route-in-laravel-4";
$obj = new Scrap;
$obj::setUrl($url); //we need to validate the link first
if($obj::checkUrl()){
echo "Title : ".$obj::getTitle()."
";
echo "Description : ".$obj::getMeta('description')."
";
echo "Author : ".$obj::getMeta('author')."
";
echo "Image : ".$obj::getImg()."
";
}else{
echo "Invalid Domain,";
}
Run it yourself. the codes above will output smth like this
Title : Accessing Controller Layout Inside Route in Laravel 4
Description : If you're using Dynamic Controller layout in Laravel, you might sometimes want to directly render the Views inside Route. This is actually not a recommended way to render views inside Route, but whatever, you're the master of your own program. bellow is how we do it in Controller :class HomeController extends BaseController { public function showHome() { now you can...
Author : https://plus.google.com/103246562201441175208
Image : http://codetrash.com/assets/images/logo.png