preg_replace regex problem

Question

I’m trying to alter the content of an email generated by a plugin, removing a lengthy section that starts with <p> NOTE: (the space is actually a tab) and ending with /</a><br /> (lines 2-5 below). There are all sorts of characters and line feeds in between. I can’t get the search to work. Here is the type of content and what I’ve tried at PHP Sandbox. I thought a non-greedy quantifier would work, but no joy.

$content = 'Weather: rainy</p>
<p> NOTE: You are entering the twilight zone:<br />
 – No cell phones</p>
<p>Click here:<br />
<a href="https://www.example.com/" rel="nofollow">https://www.example.com/</a><br />
—<br />
To exit, visit:<br />
<a href="https://example.org/wp-admin/admin.php?page=twilight;subpage=global_options" rel="nofollow">https://example.org/wp-admin/admin.php?page=twilight;subpage=global_options</a><br />
To see current twilight zone conditions, visit:<br />

$search = '~<p>sNOTE[.nr]+?/</a><br />~';
$replace = '';
$content = preg_replace($search, $replace, $content);
echo $content;
0
Jim Worrall 1 month 0 Answers 7 views 0

Leave an answer