This question already has an answer here:
- php regex to match outside of html tags 4 answers
- How do you parse and process HTML/XML in PHP? 30 answers
I would like to replace the string of text contained between opening and closing HTML tags.
This is what I've done to date:
$content =
preg_replace(
'/\b' . preg_quote( $text, "/" ) . '\b/i',
$replace",
$content
);
The tricky part is that I only wish to replace the text not part of HTML-markup, i.e. not the words in <div class="word">
or <img src="../test.img" alt="word">
-- only the text contained between HTML opening and closing tags.
How might I achieve that objective?