Ricardo Capistran Ricardo Capistran - 1 year ago 80
PHP Question

How to remove info from inside tags from a variable

I have this text in a variable, lets say $textvariable:

<p>Hello everybody I would like</p>
<p><output tipo="youtube" valor="5ZzklOEGW0w"><em>youtube: 5ZzklOEGW0w</em></output></p>
<p>to party a lot</p>
<p><output tipo="youtube" valor="RW2QkfIytRA"><em>youtube: RW2QkfIytRA</em></output></p>

And I would like to remove what's insede and leave it like this:

<p>Hello everybody I would like</p>
<p><output tipo="youtube" valor="5ZzklOEGW0w"></output></p>
<p>to party a lot</p>
<p><output tipo="youtube" valor="RW2QkfIytRA"></output></p>

I know the regex to find the info inside:


But how can I remove all information inside this tags? That can be more than one or two of this in a variable


Answer Source

You can use preg_replace

preg_replace('/(<output[^>]*>)(.*?)(<\/output>)/i', '$1$3', $html);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download