Last active
November 1, 2016 21:00
-
-
Save onigetoc/45fcd8b3ec98bcc10b850b1b6a33002d to your computer and use it in GitHub Desktop.
Get favicon V1
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 | |
// REGEX LIST | |
// $success = preg_match('/\<link.*href=\"(.*)\" \/\>/is', $str, $matches); | |
// $success = preg_match('/\<link.*href=\"(.*)\" \/\>/is', $text, $matches); | |
echo "<h2>Find RSS Feed URLs</h2>"; | |
//$url = "https://mrmondialisation.org"; | |
$url = "http://stackoverflow.com/"; | |
$favicon = iconprovider($url); | |
echo $favicon; | |
function iconprovider($url) { // Find RSS feed in a web page url - a litle bit slower | |
$icons = ""; | |
//$subject = file_get_contents($url); | |
$subject = getContent($url); | |
// serach for all 'RSS Feed' declarations | |
if (preg_match_all('#<link[^>]+rel=\s*(?:"|)(icon|shortcut icon)[^>]*>#is', $subject, $rawMatches)) { | |
// extract url from each declaration | |
foreach ($rawMatches[0] as $rawMatch) { | |
if (preg_match('#href=\s*(?:"|)([^"\s>]+)#i', $rawMatch, $rawUrl)) { | |
$icons .= $rawUrl[1].'<br>'; | |
//break; | |
} | |
} | |
} | |
$favicon = $icons; | |
//$favicon = str_replace("amp;", "", $favicon); | |
$favicon = htmlspecialchars_decode($favicon); | |
return $favicon; | |
} | |
function getContent($url) { // Find RSS feed in a web page url - a litle bit slower | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_HEADER, 0); | |
curl_setopt($ch, CURLOPT_VERBOSE, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); | |
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)"); | |
curl_setopt($ch, CURLOPT_URL, urlencode($url)); | |
$content = curl_exec($ch); | |
if( ($content = curl_exec($ch) ) === false) | |
{ | |
$content = @file_get_contents($url); | |
return $content ; | |
} | |
else | |
{ | |
return $content ; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment