Level 61
You do not need regex for that
$string = '<h1>Title</h1>';
echo str_replace(['<h1>', '</h1>'], '', $string);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi everyone,
I have this string:
<h1>Title</h1>
<p>Body Text.</p>
And I want to get rid of the <h1> tag.
I created this RegEx:
<h1>(.+)</h1>
But this does not work:
preg_replace('<h1>(.+)</h1>', '', $string)
I get this error:
ErrorException: preg_replace(): Unknown modifier '('
What's happening here?
Thank you! Jeroen
So remove it
preg_replace('/<h1>(.+)<\/h1>/', '', $string)
Please or to participate in this conversation.