我有一个加载了HTML标记的DOM对象。我试图取代,看起来像这一切嵌入标签:PHP DOM用新元素替换元素
<embed allowfullscreen="true" height="200" src="path/to/video/1.flv" width="320"></embed>
有了这样的标签:
<a
href="path/to/video/1.flv"
style="display:block;width:320px;height:200px;"
id="player">
</a>
我有麻烦搞清楚了这一点,我不希望使用正则表达式。你能帮我吗?
编辑:
这是我到目前为止有:
// 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
}
没有时间,现在写了一个答案,但检查出的http:/ /www.php.net/manual/en/class.domdocument.php – 2010-07-07 13:09:11
我看了,但我无法弄清楚。我已经用我已经有的代码更新了我的答案,但是应该切换元素的最后一行不起作用。 – 2010-07-07 13:20:21
查看类似的问题:http://stackoverflow.com/q/17864378 – 2013-07-25 22:48:45