I have this piece of HTML:
<div class="embed">
<iframe width="300" height="200" frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/123456"></iframe>
Some text I don't want
</div>
This is how it is being inserted into the HTML:
<div class="embed"><?php echo $item['embed_html']; ?></div>
This is what
$item['embed_html']
is echoing out:
<iframe width="300" height="200" frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/123456"></iframe>Some text I don't want
So I don't want to parse the whole document, just this specific string.
Don't worry, this isn't "outside user" inputted HTML, before anyone points out the security issues with allowing raw code on to a page...
I need to extract the HTML but leave the text (so it would look like this):
<div class="embed">
<iframe width="300" height="200" frameborder="0" allowfullscreen="" src="http://www.youtube.com/embed/123456"></iframe>
</div>
There are multiple different embed codes, so I guess what I'm asking is what is the best way to remove text that is not wrapped in an HTML element (between < and >) (<img, <p, <div, <iframe, <object, <embed, <video
etc may all be used in this section). Just that if there is any text added to it that is not wrapped in a tag it should remove it from the string.
I don't want to wrap the offending text in a tag, I want to completely remove it. In a way, the reverse of strip_tags()