echo <h1> in page title using PHP

Status
Not open for further replies.

jerxs

Active member
Jun 24, 2006
1,804
24
38
North East PA
Id like to some how grab whatever is between an <h1> on each page and echo that dynamically in the <title> tags for that page, using php.....

anyone know how I would go about doing this?

Thanks in advance, Jer
 


I know this is probably done wrong, but this is how I grab stuff from a page, I suck at regex :p

PHP:
<?php
$file = file_get_contents("file.htm");
preg_match_all("/<h1>([a-zA-Z]+)<\/h1>/", $file, $h1);
print_r($h1);
?>
 
that isnt working, Im going to be placing the code in a template so that each page that I use the template on it will grab the contents of the <h1> tag and place in the title.

Do you know of a source that I could read up on pulling something like this off? I have quite a few php resources, but cant find anything specific.
 
Oh well then would you just have something like this
Code:
<?php
$title = "HEADER&TITLE";
?>
<html>
<head>
<title><?=$title;?></title>
</head>
<body>
<h1><?=$title?></h1>
</body>
</html>
 
Status
Not open for further replies.