I currently have this string:
"<p><iframe allowfullscreen="" class="media-element file-default" data-fid="2219" data-media-element="1" frameborder="0" height="360" src="https://www.youtube.com/embed/sNEJOm4hSaw?feature=oembed" width="640"></iframe></p>"
I'd like to remove the whole iframe element (<iframe>...</iframe>
) and replace it with an <a>
link to the url in the src
attribute:
<p><a href="https://www.youtube.com/embed/sNEJOm4hSaw?feature=oembed">Link to youtube</a></p>
Currently, I have this regex:
$res = preg_replace('/src="(.+?)"/', '/<a href="$1">Link to youtube</a>/', $str);
With this regex, I'm able to replace the src
attribute with an a
element. However, I'd like to replace the whole iframe
element.
What is the easiest way to achieve this?