473,657 Members | 2,493 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 4138
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='Su nny 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_keyw ord("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='Su nny 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********@hot mail.com> wrote in message
news:54******** *************** ***@posting.goo gle.com...
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_keyw ord("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='Su nny 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********@hotm ail.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_keyw ord("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_keyw ord("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
15005
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 variable ($pagetitle). How do I get the value before the code for the <title> is written. This is just a
1
1396
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
1935
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 is not in the <form> section of the page. does this matter or is there a better way to programatically/dynamically set the title of the page.
8
3961
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
1584
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
1863
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 master page looks like this... <%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %>
13
1636
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. Here's how I originally structured my php pages: include header.php (contents are basically my HTML/CSS up to the <!--begin content--> point) <php code>
4
3825
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. -- thanks - dave david_at_windward_dot_net http://www.windwardreports.com
15
1909
by: Steve B | last post by:
Is there a way to manipulate the <TITLEin the csharp code?
0
8421
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8325
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.