471,316 Members | 1,465 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,316 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 3839
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

13 posts views Thread by mark | last post: by
1 post views Thread by Andreas Klemt | last post: by
6 posts views Thread by Alex | last post: by
8 posts views Thread by DC | last post: by
5 posts views Thread by Carlo Marchesoni | last post: by
13 posts views Thread by guitarromantic | last post: by
15 posts views Thread by Steve B | last post: by
reply views Thread by rosydwin | last post: by

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.