0

Hi all,

I have the following code that finds specific images, and uses an attributte to create an iframe src. ( It is for youtube videos ).

I am able to find the nodes and the attribute, but cant quite figure out how i REPLACE the found image with the newly created iframe.

Images look like this, they are from tinyMce and that is the code that i get saved to database after inserting a youtube video. Which wouldnt render on the client..

<img class="mce-object mce-object-iframe" 
src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" width="560" height="315" 
data-mce-p-frameborder="0" data-mce-p-src="//www.youtube.com/embed/NucJk8TxyRg" data-mce-object="iframe">

<img class="mce-object mce-object-iframe" 
src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" width="560" height="315" 
data-mce-p-frameborder="0" data-mce-p-src="//www.youtube.com/embed/DlOl9LOUQ0g" data-mce-object="iframe">

Here is the PHP that finds those images.

$doc = new DOMDocument();
$doc->loadHtml( $string );

$xpath  = new DOMXPath( $doc );

$val = $xpath->query( "//img[@data-mce-p-src]" );

for( $i = 0; $i < $val->length; $i++ ) 
{
   $iframe = '<div class="video-container">
   <iframe src="http:' . $val->item( $i )->getAttribute( "data-mce-p-src" ) . '" frameborder="0" width="10" height="10"
   allowfullscreen />
   </iframe>
   </div>
   <br /><br />';

   echo $iframe;
}

How do I delete these images, and replaces them with the iframe?

Its also important that i dont get a <head> etc. created from DomDocument.

Best regards, klemme

1
Contributor
1
Reply
7
Views
3 Years
Discussion Span
Last Post by klemme
0

I got it working in a different way. Turned out I was handling the tinyMce data in a way to messy way and could get the clean data via js.

I would still like to know how to do this though, so if someone cant hold back please do tell :-)

/Klemme

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.