function get_file_title($file){ $cont = file_get_contents($file); preg_match( "/(.*)<\/title>/i", $cont, $match ); return strip_tags($match[0]); } $url = $data['url']; $tag = ("$url"); if(get_file_title("$tag")) { echo get_file_title("$tag"); } else { echo $data['url']."<br>"; }