472,984 Members | 2,188 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,984 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 3920
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: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
4
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

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.