How would I use PHP's preg_replace()
to return only the value inside the <h1>
in the following string (it's HTML text loaded in a variable called $html
):
<h1>I'm Header</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Pellentesque tincidunt porttitor magna, quis molestie augue sagittis quis.</p>
<p>Pellentesque tincidunt porttitor magna, quis molestie augue sagittis quis. Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
I've tried this: preg_replace('#<h1>([.*])</h1>.*#', '$1', $html)
, but to no avail. Am I regex-ing this correctly? And is there a better PHP function that I should be using instead of preg_replace
?