Jump to content

[SOLVED] Get title?


ki

Recommended Posts

Taken from PHP.net:

 

<?php
$file = fopen ("http://www.example.com/", "r");
if (!$file) {
    echo "<p>Unable to open remote file.\n";
    exit;
}
while (!feof ($file)) {
    $line = fgets ($file, 1024);
    /* This only works if the title and its tags are on one line */
    if (eregi ("<title>(.*)</title>", $line, $out)) {
        $title = $out[1];
        break;
    }
}
fclose($file);
?> 

Link to comment
https://forums.phpfreaks.com/topic/71658-solved-get-title/#findComment-360748
Share on other sites

parser the index file of the site and read the title in

<title>blar</title>

 

something like this

 

<?php
$HTML = file_get_contents("http://www.phpfreaks.com");
preg_match_all('%<title>([^<]*)</title>%i', $HTML, $result, PREG_PATTERN_ORDER);
$result = $result[0];
echo $result;
?>

 

EDIT:

LOL,

and the winner is haaglin, for his snip from PHP.NET, which proves better that the other two LOL

Link to comment
https://forums.phpfreaks.com/topic/71658-solved-get-title/#findComment-360749
Share on other sites

the best one for, speed and bandwidth as it, stops when it finds the title..

the other read in the whole page..

 

Taken from PHP.net:

 

<?php
$file = fopen ("http://www.example.com/", "r");
if (!$file) {
    echo "<p>Unable to open remote file.\n";
    exit;
}
while (!feof ($file)) {
    $line = fgets ($file, 1024);
    /* This only works if the title and its tags are on one line */
    if (eregi ("<title>(.*)</title>", $line, $out)) {
        $title = $out[1];
        break;
    }
}
fclose($file);
?> 

Link to comment
https://forums.phpfreaks.com/topic/71658-solved-get-title/#findComment-360752
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.