I need to get the <title> from any given url, and my script works fine normally but sometimes I come across a page that give me a 403 error and it won't grab the title. Any suggestions? The errors I get when I change the code around all have HTTP request failed! HTTP/1.0 403 Forbidden in them.
Here's my script:
Code: Select all
$file = @file_get_contents($link);
if(preg_match("/<title>(.+)<\/title>/i",$file,$m)) {
$title = $m[1];
$title = strip_tags(addslashes(trim(preg_replace("/&#?[a-z0-9]{2,8};/i","",$title))));
}
else {
$title = '';
}