Reputation: 2281
Gived a string so formed:
hello Rose <tag> Micheal </tag> and <tag> July </tag> John.
I want remove all between <tag>
and </tag>
and to have in output:
hello Rose and John.
how i can it?
Upvotes: 4
Views: 50
Reputation: 98921
I guess you can use:
$new_html = preg_replace('%<tag>.*?</tag> ?%si', '', $old_html);
Upvotes: 6
Reputation: 1233
If you do not want to use DOM, you could always use preg_replace to do this.
$content = 'hello Rose <tag> Micheal </tag> and <tag> July </tag> John.';
$content = preg_replace('/<tag>[^<]+<\/tag>/i', '', $content);
print $content; // returns: hello Rose and John.
Upvotes: 0