Created
September 5, 2012 22:25
-
-
Save oritromax/3646360 to your computer and use it in GitHub Desktop.
A simple Function to Fetch Webpage Title and Description And Excerpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// The Use of fetcher.function.php - Oritro Ahmed | |
//[www.oritro.com] | |
//Filename: fetcher.php | |
//Usefull for Link Shortener, link generator, Backlink generator | |
// A part Of Tankz Easy PHP Use Scripts | |
$url = 'http://www.oritro.com/'; | |
$content = file_get_contents($url); | |
$title = getMetaTitle($content); | |
$description = getMetaDescription($content); | |
$excerpt = getExcerpt($content); | |
print "title ==> $title "; | |
print "< br />"; | |
print "description ==> $description "; | |
print "< br />"; | |
print "excerpt ==> $excerpt"; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// A simple Function To Fetch Details Of a Webpage- Oritro Ahmed | |
//[www.oritro.com] | |
//Filename: fetcher.function.php | |
//Usefull for Link Shortener, link generator, Backlink generator | |
// A part Of Tankz Easy PHP Use Scripts | |
// This Will Bring the <title></title> Of the Webpage | |
function getMetaTitle($content){ | |
$pattern = "|<[\s]*title[\s]*>([^<]+)<[\s]*/[\s]*title[\s]*>|Ui"; | |
if(preg_match($pattern, $content, $match)) | |
return $match[1]; | |
else | |
return false; | |
} | |
// This Will Bring The Description | |
function getMetaTitle($content){ | |
$pattern = "|<[\s]*title[\s]*>([^<]+)<[\s]*/[\s]*title[\s]*>|Ui"; | |
if(preg_match($pattern, $content, $match)) | |
return $match[1]; | |
else | |
return false; | |
} | |
//Basically It will Read the Entire page first | |
//Then it will look for the first Paragraph Tag <p> </p> | |
//And Bring Whatever Inside It. | |
function getExcerpt($content) { | |
$text = html_entity_decode($content); | |
$excerpt = array(); | |
//match all tags | |
preg_match_all("|<[^>]+>(.*)]+>|", $text, $p, PREG_PATTERN_ORDER); | |
for ($x = 0; $x < sizeof($p[0]); $x++) { | |
if (preg_match('< p >i', $p[0][$x])) { | |
$strip = strip_tags($p[0][$x]); | |
if (preg_match("/\./", $strip)) | |
$excerpt[] = $strip; | |
} | |
if (isset($excerpt[0])){ | |
preg_match("/([^.]+.)/", $strip,$matches); | |
return $matches[1]; | |
} | |
} | |
return false; | |
} | |
?> | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment