Jump to content


Photo

How to get <title> info from previous page?


  • Please log in to reply
5 replies to this topic

#1 Allen4172

Allen4172
  • Members
  • PipPip
  • Member
  • 17 posts

Posted 15 June 2006 - 04:39 AM

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 :)

#2 phpvolution

phpvolution
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 15 June 2006 - 05:07 AM

Hey Mike,
just pass the variable with the link:

<?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>

that should do it

#3 Michael4172

Michael4172
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 15 June 2006 - 09:26 AM

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

<?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>

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.

#4 Lorian

Lorian
  • Members
  • PipPip
  • Member
  • 19 posts
  • LocationUnited Kingdom

Posted 15 June 2006 - 11:14 AM

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...?
Chris Spencer [ aka Lorian ]

[span style=\'font-size:8pt;line-height:100%\']PHP Freaks Community Member
Contact me: corrosivechris (at) gmail d0t com[/span]

#5 Michael4172

Michael4172
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 15 June 2006 - 06:57 PM

[!--quoteo(post=384127:date=Jun 15 2006, 07:14 AM:name=Lorian)--][div class=\'quotetop\']QUOTE(Lorian @ Jun 15 2006, 07:14 AM) View Post[/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.

#6 Michael4172

Michael4172
  • Members
  • PipPipPip
  • Advanced Member
  • 41 posts

Posted 15 June 2006 - 08:55 PM

I found what I was looking for in $_SERVER['HTTP_REFERER']





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users