从txt文件中读取链接

this code not display title when i get link from txt file

<?php
function page_title($url) {
    $fp = file_get_contents($url);
    if (!$fp) 
        return null;

    $res = preg_match("/<title>(.*)<\/title>/siU", $fp, $title_matches);
    if (!$res) 
        return null; 

    // Clean up title: remove EOL's and excessive whitespace.
    $title = preg_replace('/\s+/', ' ', $title_matches[1]);
    $title = trim($title);
    return $title;
}

$file = fopen("link.txt","r");
$lien = fgets($file);
fclose($file);

print page_title($lien);

?>

this code not display title when i get link from txt file

blank screen

my link.txt countains :

http://google.com

When I run this code i get the word "Google" displayed on my screen. So i have to think that your code is doing what you want but that there is some other, perhaps host-specific, problem here.

OK I just broke it by putting a CR in the text file after the URL and I fixed it by changing

$lien = fgets($file);

to

$lien = trim(fgets($file));