Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


php dom replace element with a new element using -'php,dom'


php dom replace element with a new element  using -'php,dom'

I have a DOM object with loaded HTML markup. I'm trying to replace all embed tags that look like this:

<embed allowfullscreen="true" height="200" src="path/to/video/1.flv" width="320"></embed>


With a tag like this:

<a
href="path/to/video/1.flv"
style="display:block;width:320px;height:200px;"
id="player">
</a>


I'm having troubles figuring this out and I don't want to use regular expression for this. Could you help me out?

EDIT:

This is what I have so far:

         // DOM initialized above, not important
            foreach ($dom->getElementsByTagName('embed') as $e) {
                $path = $e->getAttribute('src');
          $width = $e->getAttribute('width') . 'px';
          $height = $e->getAttribute('height') . 'px';
          $a = $dom->createElement('a', '');
          $a->setAttribute('href', $path);
          $a->setAttribute('style', "display:block;width:$width;height:$height;");
          $a->setAttribute('id', 'player');
          $dom->replaceChild($e, $a); // this line doesn't work
      }

    

asked Sep 7, 2015 by rajesh
0 votes
4 views



Related Hot Questions



Walkin Jobs Opening



Government Jobs Opening


...