Reputation: 51224
Is there I simple way to get contents of a <h1>
tag from a html file, using PHP (or Smarty), on the server side?
Background is that I need to do some SEO on a legacy Smarty based PHP site, with bunch of content pages with no head section defined.
I.e., the main index.php
page loads a shared index.tpl
template which contains the <head>
section along with <title>
and meta description tags for all pages, and then just grabs the content from individual pXXX.html
, based on an id
parameter in the url. Each "content" page has an <h1>
tag where the relevant title is stored, but the page title remains fixed all the time.
Since there is too many of them to edit each of them individually, I wanted to see if I could get their each by parsing the page on request. I guess I could make a script which would do some batch processing, but I am looking for a quick solution which wouldn't modify these content pages.
I am open to other suggestions, also. To be honest, I never used Smarty before, so I might be missing something here.
Upvotes: 1
Views: 1779
Reputation: 41050
preg_match('~<h1>(.+)</h1>~', file_get_contents('original_file.html'), $result);
var_dump($result[1]);
Upvotes: 1
Reputation: 25312
Well, in index.php you could :
Upvotes: 1