Using the <h2> as the title after sent?

Posted by Delan Azabani on Stack Overflow See other posts from Stack Overflow or by Delan Azabani
Published on 2010-06-13T09:26:22Z Indexed on 2010/06/13 9:32 UTC
Read the original article Hit count: 248

Filed under:

Currently, I have a semi-dynamic system for my website's pages. head.php has all the tags before the content body, foot.php the tags after. Any page using the main theme will include head.php, then write the content, then output foot.php. Currently, to be able to set the title, I quickly set a variable $title before inclusion:

<?php $title = 'Untitled document'; include_once '../head.php'; ?>
<h2>Untitled document</h2>
Content here...
<?php include_once '../foot.php'; ?>

So that in head.php...

<title><?php echo $title; ?> | Delan Azabani</title>

However, this seems kludgy as the title is most of the time, the same as the content of the h2 tag. Is there a way I can get PHP to read the content of h2, track back and insert it, then send the whole thing at the end?

© Stack Overflow or respective owner

Related posts about php