Jump to content

Page Title


tcorbeil

Recommended Posts

I have another post on here for this problem but I think I have overcomplicated the matter.. Ok in it's simplest form: Is there a way to retrieve the current page title and place it into a PHP variable?

 

something like"

 

$pagetitle = **** Title of the current page I'm viewing ****

 

Thanks in advance.

 

T.

Link to comment
https://forums.phpfreaks.com/topic/43015-page-title/
Share on other sites

Well let's say this is your code, ok?

 

<html> <title>This is the page title we want</title></html>
<?php

$pagetitle = "This is the page title we want";

?>

 

That is essentially the ultimate goal correct?

 

What is the scenario, are you including an html file in this script and you want to get the data that was already printed via the html file? If so one way to do it is to parse the html file before or after the include. IE:

 

--------Display.html-----------
<html> <title>This is the page title we want</title></html>
--------End Display.html---------

---------index.php-----------
<?php
include('display.html');

$displayTitle = file_get_contents('display.html');
list($title) = spliti('</title>', $displayTitle);
list(,$pagetitle) = spliti('<title>', $title);

print $pagetitle;

?>
--------End index.php

 

Now if it is not, are you trying to fetch the file from another webserver, let's say off of google.com if that is the case it would be done similarly to the code above except the file_get_contents parameter would be different.

 

 

Link to comment
https://forums.phpfreaks.com/topic/43015-page-title/#findComment-209043
Share on other sites

Thanks for the replies.. actually, it is the opposite that I want.. Let's say I have a huge datatbase on mySQL. Within it I have a table called 'Entertainment'..  that table would look something like :

 

Here are the colums...

 

Index            Page title            some data here            some data here

--------------------------------------------------------------------------

 

Here are the rows filled out as such..

 

1                xbox.php              xxxxxxxxxxx                  xxxxxxxxxxx

2                nintendo.php        xxxxxxxxxxx                  xxxxxxxxxxx

3                sony.php            xxxxxxxxxxx                    xxxxxxxxxxx

4                xbox.php              xxxxxxxxxxx                  xxxxxxxxxxxx

 

The pages xbox.php, nintendo.php, sony.php all belong to my site.

 

Right now I retreive the entries with: (assuming I am loading www.xxxx.com/xbox.php)

 

$index_id="xbox.php";

$query="SELECT * FROM `Entertainment` WHERE Page ='$index_id'";

$result=mysql_query($query);

 

 

So when I print the display on the screen, only the entries that list xbox.php are listed from the table.. 

Now this works.. but, I have to declare that variable "$index_id" beforehand..

 

Because my site will have many pages with different names to them, I don't want to edit them all when I make minor changes.. If i could do something like: (Again, assuming I'm loading the page www.xxxx.com/xbox.php)

 

 

$index_id= fetch the name of the page that is currently loading (in this case xbox.php)

$query="SELECT * FROM `Entertainment` WHERE Page ='$index_id'";

$result=mysql_query($query);

 

So that ultimatley if I have another page called sony.php, I don't have to change the value of $index_id.. it just fetched the value on it's own and retreives, from my table, the appropriate info..

 

Again, thanks to all for your help.

 

T.

 

 

Link to comment
https://forums.phpfreaks.com/topic/43015-page-title/#findComment-209096
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.