Getting the page title of another page?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jaceinla
Forum Commoner
Posts: 25
Joined: Thu Oct 14, 2010 12:57 pm

Getting the page title of another page?

Post by jaceinla »

Hi all,

Is it possible to retrieve the page title of another page via php? I'd like to set up a link on PAGE A that points to PAGE B and create it so that:

Code: Select all

<a href="pageB"><?php constant changing title of page B ?></a>
Thanks!
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Getting the page title of another page?

Post by Celauran »

Code: Select all

$contents = file_get_contents($pageB);
$title = substr($contents, (stripos($contents, '<title>') + 7), (stripos($contents, '</title>') - stripos($contents, '<title>')));
echo "<a href=\"{$pageB}\">{$title}</a>";
jaceinla
Forum Commoner
Posts: 25
Joined: Thu Oct 14, 2010 12:57 pm

Re: Getting the page title of another page?

Post by jaceinla »

I didn't know file_get_contents can take a URL, thanks.
Post Reply