Hi,
I need to remove all between open and close tag.
For example:
Text Text Text
<sometag>
Text1 in Tag!!!
</sometag>
Text 2 Text 2 Text 2
<sometag>
Text2 in Tag!!!
</sometag>
Text 3 Text 3 Text 3
<sometag>
Text3 in Tag!!!
</sometag>
I want to show only this as Result:
Text Text Text
Text 2 Text 2 Text 2
Text 3 Text 3 Text 3
Here is my code:
preg_replace('/<sometag>.*<\/sometag>/sm', '', $text);
But this regexp doesn't show anything.
Could you help me, please
Remove all between tags problem
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Remove all between tags problem
Your regexp is removing everything from (and including) the first tag to the last. Maybe try preg_split() with either <sometag> or </sometag> and you will get an array of the contents. You can also use the XML parsing functions to read the contents.
(#10850)
Re: Remove all between tags problem
Or try a non-greedy match by using .*? instead of .*