You can do it with regex and file functions, though it's not exactly simple. A better way to do it would be to have your content seperated from the rest of the document. Most people have seperate header, body, and footer files.
eg:
<?php
include("header.php");
//some body content here
include("footer.php");
?>
Many also use a database to store their information.
In either of these scenarios you could simply include the content without messy regex/file functions. That's the beauty of seperating data from formatting. Sorry that doesn't exaclty answer your question, but at least it's a start.