Tengo un objeto DOM con etiquetas HTML cargadas. Estoy tratando de reemplazar todas las etiquetas embed que se ven así:PHP DOM elemento de reemplazo con un nuevo elemento
<embed allowfullscreen="true" height="200" src="path/to/video/1.flv" width="320"></embed>
Con una etiqueta como esta:
<a
href="path/to/video/1.flv"
style="display:block;width:320px;height:200px;"
id="player">
</a>
estoy teniendo problemas calcular esto y yo no quiero usar expresión regular para esto. ¿Podrías ayudarme?
EDIT:
Esto es lo que tengo hasta ahora:
// 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
}
no tiene tiempo para escribir una respuesta ahora, pero echa un vistazo a http://www.php.net/manual/en/class.domdocument.php –
Lo he buscado pero no lo puedo descifrar. He actualizado mi respuesta con el código que ya tengo, pero la última línea, que se supone que debe cambiar los elementos, no funciona. –
Ver pregunta similar: http://stackoverflow.com/q/17864378 –