473,473 Members | 1,959 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Page Title

Is it possible to return the Page title in php ?

I can return the end of the url with $_SERVER["PHP_SELF"] however it
is the "Page Title" that I require.

Thanks
Jun 2 '08 #1
2 1473
Stuartsblog wrote:
Is it possible to return the Page title in php ?

I can return the end of the url with $_SERVER["PHP_SELF"] however it
is the "Page Title" that I require.
Not really. The Title is part of the response your script generates.
PHP_SELF is a value given by your Webserver and more representing the
request that cases your skript to run.

Heiko
Jun 2 '08 #2
On Thu, 15 May 2008 20:53:55 +0200, Stuartsblog
<st****@stuartstuart.fsnet.co.ukwrote:
Is it possible to return the Page title in php ?

I can return the end of the url with $_SERVER["PHP_SELF"] however it
is the "Page Title" that I require.
Not just like that. To PHP, all previous output is just a random string
for all it's concerned. If the page title of the current page is of
importance, you should know it earlier on, or at least save it. If you're
in the habit of just maxing PHP & HTML, teach yourself to prepare all data
in strings before any output is generated, and just ending it with a
outputting HTML and the previous data stored.

An illustration, if your page is kind of like this:
<html>
<head><title><?php echo some_function_output(); ?></title>
<body>
<?php
mysql_connect(...);
$r =mysql_query('SELECT data FROM table');
$data = mysql_fetch_assoc($r)
echo $data['data'];
//euhm, title change?
?>
</body>
</html>

Change it to this:

<?php
$title = some_functions_output();
mysql_connect(...);
$r =mysql_query('SELECT data FROM table');
$data = mysql_fetch_assoc($r)
$content = $data['data'];
//title change
$title .= 'output succeeded';
?>
<html>
<head><title><?php echo $title; ?></title>
<body>
<?php echo $content; ?>
</body>
</html>
If that cannot be done, or you need a quick fix, here is some majorly
dirty code I'd slap a previous coder for using:

<?php
ob_start();
function get_title(){
$send_so_far = ob_get_contents();
if(preg_match('@<title[^>]*>(.*?)</title>@si',$send_so_far,$match)){
return $match[1];
}
return false;
}
?>
<html>
<head><title>foobar</title>
<body>
<?php echo get_title(); ?>
</body>
</html>

--
Rik Wasmus
[SPAM] Now temporarily looking for some smaller PHP/MySQL projects/work to
fund a self developed bigger project, mail me at rik at rwasmus.nl. [/SPAM]
Jun 2 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: the wonderer | last post by:
This is an elementary question, but I've not been able to find the answer, so here goes: I am developing a site using php. I have the html header information in a file that I include in all the...
6
by: Don Grover | last post by:
How can I get the page title into an variable to handle in my asp. Don
1
by: alex | last post by:
Hi ! I couldn't make backups with our new system using db2 8.2. Every time I trigger a backup I get this error message: BACKUP DATABASE EBUERO2 ONLINE TO "/raid/backup/ebuero2/part1",...
5
by: Maxim Izbrodin | last post by:
Hello For displaying page titles for my ASP.NET applications I use the following technique <title><%=BannerModule.PageTitle%></title where BannerModule.PageTitle is a public field of my user...
4
by: Glenn M | last post by:
I have a shared XML file on a server . i also have one xslt file that performs a simple transform on in to view the data. now i want to have another page that lets users modify the shared xml...
14
by: Paul | last post by:
I want to set the page title and/or a form hidden field programatically through ASP.Net. I do not want to use something like... <% sTitle ="My Title" %> <html><title><%=sTitle%></title>..... ...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
1
by: vj | last post by:
How i can populate all fileds dynamically in jsp page based on contents found in xml file? I have written jsp servlets and java class file. i transferred automatic data from jsp to servlet then to...
0
by: Spondishy | last post by:
Hi, I have a fairly simple httpmodule tied in to the endrequest event of the pipeline that writes the page title to the iis log. The problem is, I have a page where the title is changed in the...
4
osward
by: osward | last post by:
I had made a table colum sortable and paging the table, following are the code // Display Event List echo "<center>"._EVENTLIST."</center><br>"; $now = Date(Y-m-d); // sort table...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.