Yüklü HTML işaretlemesi olan bir DOM nesnesine sahibim. Böyle bir etiketi ilePHP DOM öğeyi yeni bir öğeyle değiştir
<embed allowfullscreen="true" height="200" src="path/to/video/1.flv" width="320"></embed>
: Ben şuna benzer Tüm gömme etiketleri değiştirmek çalışıyorum
<a
href="path/to/video/1.flv"
style="display:block;width:320px;height:200px;"
id="player">
</a>
bu endam sorun yaşıyorum ve ben kullanmak istemiyorum Bunun için düzenli ifade. Bana yardım edebilir misin?
DÜZENLEME: getElementsByTagName
kullanarak bir DOM unsurları bulmak kolaydır
// 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
}
şu anda bir cevap yazmak için zaman var, ancak kontrol etme http://www.php.net/manual/en/class.domdocument.php –
Baktım ama anlayamıyorum. Cevabımı halihazırda sahip olduğum kodla güncelledim ama eleman değiştirmesi gereken son satır çalışmıyor. –
Benzer bir soruya bakın: http://stackoverflow.com/q/17864378 –