Replace only the text content of HTML tag [duplica

2019-06-08 17:45发布

This question already has an answer here:

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?

0条回答
登录 后发表回答