473,396 Members | 1,766 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Retrieve <TITLE> in php code ?

Hi there,

Simple question, but headache !

I have a PHP Page like :

<HTML>
<HEAD>
<TITLE>Sunny day !</TITLE>
</HEAD>
<BODY>
<?
echo "The title of this page please (Sunny Day !)"
?>
</BODY>
</HTML>

I think that you have understanding my problem : How to retrieve the
title of my page ?

Very very thanks in advance !

Michel
Jul 17 '05 #1
5 4114
Info 3000 wrote:
I have a PHP Page like :

<HTML>
<HEAD>
<TITLE>Sunny day !</TITLE>
</HEAD>
<BODY>
<?
echo "The title of this page please (Sunny Day !)"
?>
</BODY>
</HTML>

I think that you have understanding my problem : How to retrieve the
title of my page ?


I'd look at it differently:

<html>
<head>
<!-- set and print $page_title -->
<title><?php echo $page_title='Sunny Day !'; ?></title>
</head>
<body>
<?php
// use saved $page_title
echo 'The title of this page is (', $page_title, ')';
?>
</body>
</html>

--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2
Thank you for this tip, but for the use that I want, it's necessary to
retrieve the real TITLE... No way, is it your last word ? No function
like get_title, or get_header_keyword("TITLE") or anything ?

Only way is to write my own function, sure ?
<HTML>
<HEAD>
<TITLE>Sunny day !</TITLE>
</HEAD>
<BODY>
<?
echo "The title of this page please (Sunny Day !)"
?>
</BODY>
</HTML>

I think that you have understanding my problem : How to retrieve the
title of my page ?

I'd look at it differently:

<html>
<head>
<!-- set and print $page_title -->
<title><?php echo $page_title='Sunny Day !'; ?></title>
</head>
<body>
<?php
// use saved $page_title
echo 'The title of this page is (', $page_title, ')';
?>
</body>
</html>

Jul 17 '05 #3
"Info 3000" <tr********@hotmail.com> wrote in message
news:54**************************@posting.google.c om...
Thank you for this tip, but for the use that I want, it's necessary to
retrieve the real TITLE... No way, is it your last word ? No function
like get_title, or get_header_keyword("TITLE") or anything ?

Only way is to write my own function, sure ?
<HTML>
<HEAD>
<TITLE>Sunny day !</TITLE>
</HEAD>
<BODY>
<?
echo "The title of this page please (Sunny Day !)"
?>
</BODY>
</HTML>

I think that you have understanding my problem : How to retrieve the
title of my page ?


I'd look at it differently:

<html>
<head>
<!-- set and print $page_title -->
<title><?php echo $page_title='Sunny Day !'; ?></title>
</head>
<body>
<?php
// use saved $page_title
echo 'The title of this page is (', $page_title, ')';
?>
</body>
</html>

Try this:

//Read the HTML file into an array:
$HTML_file = file ('http://www.example.com/');

//Convert this to a string separated by zero length strings:
$HTML_string = implode('', $HTML_file);

// then use a regexp to find what lies between the title tags:
eregi("<title>(.*)</title>", $HTML_string, $my_temp);

// $my_temp is now an array of matched patterns from the regexp:
// the first (and only, in this case) parenthesised pattern is at array
offset 1,
// which is where we will find our title:
$HTML_title = trim($my_temp[1]);

HTH
Doug
--
Remove the blots from my address to reply
Jul 17 '05 #4
tr********@hotmail.com (Info 3000) schrieb:
Thank you for this tip, but for the use that I want, it's necessary to
retrieve the real TITLE... No way, is it your last word ? No function
like get_title, or get_header_keyword("TITLE") or anything ?


Well, there might be a way. Somehow you have to get the HTML output in
your program. Have a look at the output control functions at
http://www.php.net/manual/en/ref.outcontrol.php.

The idea is to catch the output in a buffer, search the buffer for the
title and replace a placeholder in the HTML otput with the title. Have a
look at the following code:

<?php ob_start(); // start output buffering ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Yeah, it works</title>
</head>
<body>
The title of this page is: {TITLE}
</body>
</html>
<?php
// get the content of the buffer and clear the buffer
$content = ob_get_clean();
// find title
if (preg_match("~<title>(.*)</title>~iU", $content, $match)) {
// replace the placeholder {TITLE} with the real title
$content = preg_replace("~(\{TITLE\})~", $match[1], $content);
}
// output the result
echo $content;
?>

It worked for me. If you're using a PHP version < 4.3.0 you won't have
the function ob_get_clean(). This function can be replaced by two other
functions. Check the documentation if you need to.

Regards,
Matthias
Jul 17 '05 #5
I noticed that Message-ID:
<54**************************@posting.google.com > from Info 3000
contained the following:
Thank you for this tip, but for the use that I want, it's necessary to
retrieve the real TITLE... No way, is it your last word ? No function
like get_title, or get_header_keyword("TITLE") or anything ?

Only way is to write my own function, sure ?


How is the page generated?

--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #6

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

Similar topics

13
by: mark | last post by:
IF I have something like this: <title><?php print($pagetitle); ?></title> <body> <?php include("folders/my_include.php"); ?> </body> </html> and my_include.php contains the value to the...
1
by: Andreas Klemt | last post by:
Hello, I have in my strHtml a html page. so what is the fastest way (with XML Read?) to get the "myValue" between <title>myValue</title> Thanks, Andreas
6
by: Alex | last post by:
Hi, is it possible to set the title programatically from the code behind page. I placed a literal in the head section of the form and set its text property. it seemed to work bu the literal...
8
by: DC | last post by:
In HTML page, I put: <html> <head> <title>Article: <asp:Label ID="lblHTMLTitle"></asp:Label> </title> .... In the code behind: ....
5
by: Carlo Marchesoni | last post by:
Is it possible to change the document's title property from code behind (c#) ? I need to build a dynamic title at runtime.
1
by: Alan Silver | last post by:
Hello, I am just experimenting with master pages, and am trying to add a content placeholder in the <head> section, so that individual pages can set their own page title and meta tags. The...
13
by: guitarromantic | last post by:
Hey everyone. I'm editing some stuff I did last summer, trying to bugfix and improve stuff. One improvement (or an oversight of the original design) is adding dynamic <title> tags to my pages....
4
by: David Thielen | last post by:
Hi; If I am using master pages, how do I set the <title> and <meta name='description' content='my title'> for each page. Obviously each page will have a different title & description. --...
15
by: Steve B | last post by:
Is there a way to manipulate the <TITLEin the csharp code?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...

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.