Re: altering titles to fit includes
| From: | David Robley | Date: | Mon, 04 Sep 2000 02:29:25 +0000 |
| Subject: | Re: altering titles to fit includes | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-15036@lists.php.net to get a copy of this message | ||
On 2 Sep, Splitskull wrote:
>
> i'm not sure this is the right page to post this on, but maybe someone can
> help anyway.
> i have a php4 page, which includes html files for the body of the text, and
> i would like this page to be able to show its title according to the defined
> $title in the included page, but I can not for the life of me get it to
> work. i think its a little more complicated than i imagined. does anyone
> know the code setup i can use to do this?
> --
> Cody Merrill
> 38494034
> Splitskull@home.com
I use this function to grab the <TITLE> from a document in an
auto_prepend, then put the title where it will do the most good. I
expect that having two <TITLE> tags in the document will come back and
bite me someday, however :-)
function get_title($target) {
/* This little function will open the file passed in as $target and extract the TITLE
tag and the text contained therein. If nothing is found it returns a default value. */
$contents = File($target);
$exists=0;
$title = "";
for($i=0; $i < count($contents);$i++){
if(eregi("<TITLE>", $contents[$i])):
$exists=true;
endif;
if($exists):
$title .= $contents[$i];
endif;
if(eregi("</TITLE>", $contents[$i])):
break;
endif;
} /* End FOR */
/* Get rid of end of line */
$title = eregi_replace(10, "", $title);
$title = eregi_replace(13, "", $title);
if( (empty($title)) || (strtoupper($title) == "<TITLE></TITLE>")):
$title = '<TITLE>Default Title</TITLE>';
endif;
/* Clear the slashes, in case there are wonky chars in the title (Thanks, James!) */
return stripslashes($title);
} /* End function get_title */
--
David Robley | WEBMASTER & Mail List Admin
RESEARCH CENTRE FOR INJURY STUDIES | http://www.nisu.flinders.edu.au/
AusEinet | http://auseinet.flinders.edu.au/
Flinders University, ADELAIDE, SOUTH AUSTRALIA