Jump to content

[SOLVED] Get title?


ki

Recommended Posts

How do you get the title of a(n) external webpage? Ive seen it done on the vBulletin's software. Anyone know how to exactly do this? Or is there a PHP function already added to the PHP software that I don't know about.

Link to comment
Share on other sites

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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.