[eluser]felyx[/eluser]
Stupid me of course the regex was the problem and my blurry eyes hehe
Thank you for pointing me in the right direction!
I have also rewritten a couple of things as now the get_meta_tags() function will return all meta tags in an associative array.
Here is the final code:
Code:
function get_title_data($url)
{
$title = "";
urlencode($url);
$cont = @file_get_contents($url);
if ($cont != FALSE) {
$title_exists = preg_match( "/<title>(.*)<\/title>/i", $cont, $match );
if ($title_exists)
{
$title = strip_tags(@$match[ 1 ]);
return $title;
} else
{
return FALSE;
}
} else {
return FALSE;
}
}
function get_meta_data($url)
{
$meta = array();
urlencode($url);
$cont = @file_get_contents($url);
if ($cont != FALSE) {
$meta_exists = trim(preg_match_all("/<meta[^>]+(name|http-equiv)=\"([^\"]*)\"[^>]+content=\"([^\"]*)\"[^>]*>/i", $cont, $out, PREG_PATTERN_ORDER));
if ( ($meta_exists != FALSE) AND ($meta_exists > 0) )
{
for ($i=0;$i < count($out[2]);$i++) {
$meta[strtolower($out[2][$i])] = $out[3][$i];
}
return $meta;
} else {
return FALSE;
}
} else {
return FALSE;
}
}
Much cleaner, as short as it can be. Maybe someone else will find this usefull.