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