Jump to content

How to get <title> info from previous page?


Allen4172

Recommended Posts

I'm writing an a script where a user can click a link, and it'll bring up an email type prompt where they can email an article link of the story to a friend and so forth.

I see it all the time on other sites, but am curious how I would get the <title> or subject of that article dynamically? Any ideas or recomendations would be much appreciated :)
Link to comment
Share on other sites

Hey Mike,
just pass the variable with the link:

[code]
<?php
$page = file_get_contents("page.php");
preg_match('!<title>(.*?)</title>!is', $page, $match);
$title = $match[1];
?>
<a href="emailpage.php?title=<?=$title?>">e-mail this article to a friend</a>
[/code]

that should do it
Link to comment
Share on other sites

[!--quoteo(post=384080:date=Jun 15 2006, 01:07 AM:name=phpvolution)--][div class=\'quotetop\']QUOTE(phpvolution @ Jun 15 2006, 01:07 AM) [snapback]384080[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hey Mike,
just pass the variable with the link:

[code]
<?php
$page = file_get_contents("page.php");
preg_match('!<title>(.*?)</title>!is', $page, $match);
$title = $match[1];
?>
<a href="emailpage.php?title=<?=$title?>">e-mail this article to a friend</a>
[/code]

that should do it
[/quote]

Thanks for the info :)

However, that begs the question, what if I won't always know the previous page? How would I get that info? As my site is a CMS that has hundreds of possible pages.
Link to comment
Share on other sites

[!--quoteo(post=384127:date=Jun 15 2006, 07:14 AM:name=Lorian)--][div class=\'quotetop\']QUOTE(Lorian @ Jun 15 2006, 07:14 AM) [snapback]384127[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Well if you don't know the previous page, then how to you expect to be able to go to that page and get the contents of the title tag...?
[/quote]

That was my question. I am not wanting to install this manually on every page (doing this manually for hudnreds of pages is not practical). Like I said this is a dynamic type application, which means that I won't know the page. However I am thinking if there is a referrer type variable that I may use.
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.