Hello friends, could you help me? I have this html code
<div class="media_embed">
<script height="" width="">
(function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(d.getElementById(id))return;js=d.createElement(s);js.id=id;js.src='https://embed.playbuzz.com/sdk.js';fjs.parentNode.insertBefore(js,fjs);}(document,'script','playbuzz-sdk'));
</script>
<div class="playbuzz" data-id="b" data-show-info="false" height="" width=""></div>
</div>
and I have to change it to be like this:
<figure class="op-interactive">
<iframe>
<script height="" width="">
(function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(d.getElementById(id))return;js=d.createElement(s);js.id=id;js.src='https://embed.playbuzz.com/sdk.js';fjs.parentNode.insertBefore(js,fjs);}(document,'script','playbuzz-sdk'));
</script>
<div class="playbuzz" data-id="b" data-show-info="false" height="" width=""></div>
</iframe>
</figure>
but we are when the div
has class media_embed
and within div
class playbuzz
try it this way:
$media_embed = $doc->getElementsByTagName('div');
foreach ($media_embed as $media) {
$scriptstag = $media->getElementsByTagName('script');
foreach ($scriptstag as $scripts) {
$src= $scripts->getAttribute('src');
$posgif = strpos($src, 'playbuzz');
if ($posgif === false) {
} else {
$tagsscript = $media->childNodes->item(1);
//print_r($tagsscript);
$tagdiv = $media->childNodes->item(2);
//print_r($tagdiv);
$figureNuevo = $doc->createElement('figure');
$figureNuevo->setAttribute('class','op-interactive');
$iframeNuevo = $doc->createElement('iframe');
$iframeNuevo->setAttribute('class','no-margin');
$figureNuevo->appendChild($iframeNuevo);
$iframeNuevo->appendChild($tagdiv);
//$iframeNuevo->appendChild($tagsscript);
$scripts->parentNode->replaceChild($figureNuevo, $scripts);
}
}
}
Could you help me please? greetings