-3

I'm trying to clean up a large text using PHP by removing certain phrases which relate to other texts which I do not have. These phrases are typically between two html tags like <i>this</i> but I would like to remove only those which containing a keyword, which is "See also".

Is there a way to do this with preg_replace ?

Given the following input:

<h1>this is a header</h1>
<i>See also staying safe in Taiwan</i>
<p>Some long text here</p>
<i>Some more text over here</i>
<p>Some more text <i>here</i></p>

How can I remove the entire phrase containing the string "See also". Expected output:

<h1>this is a header</h1>
<p>Some long text here</p>
<i>Some more text over here</i>
<p>Some more text <i>here</i></p>

The thing to look out for is "See also".

Thank you!

James
  • 458
  • 1
  • 6
  • 18

1 Answers1

0

This is how I resolved it:

$text = preg_replace("/<i>(See also)([^<]*)<\/i>/i",'', $text);
James
  • 458
  • 1
  • 6
  • 18