[請益] php dom getElementById

看板PHP作者 (托兒所嬰兒)時間18年前 (2007/12/23 09:09), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/1
<? $dom = new DOMDocument('1.0', 'utf-8'); $r = $dom->createElement('palette'); $dom->appendChild($r); $b = $dom->createElement( 'color','green'); $r->appendChild( $b ); $id=$dom->createAttribute('id'); $b->appendChild($id); $idNum=$dom->createTextNode('1'); $id->appendChild($idNum); $b= $dom->createElement( 'color','black'); $r->appendChild( $b ); $id=$dom->createAttribute('id'); $b->appendChild($id); $idNum=$dom->createTextNode('2'); $id->appendChild($idNum); $b= $dom->createElement( 'color','blue'); $r->appendChild( $b ); $id=$dom->createAttribute('id'); $b->appendChild($id); $idNum=$dom->createTextNode('3'); $id->appendChild($idNum); echo $dom->saveXML($dom->getElementById('1')); ?> 我想藉由getElementById取得<color>裡面的元素 例如如code中的 echo $dom->saveXML($dom->getElementById('1')); 我想取得id=1的color 應該要出現"green" 沒想到跑的結果卻是 "greenblackblue " 1.請問各位大大 要怎樣才能讓他就由id取得green 2.我想讓id值為數字 有相關的function嗎? 先在這邊謝謝大大幫我解決問題 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 61.224.207.6 ※ 編輯: yorjing 來自: 61.224.207.6 (12/23 09:12) ※ 編輯: yorjing 來自: 61.224.207.6 (12/23 09:12)
文章代碼(AID): #17RRKyG1 (PHP)
文章代碼(AID): #17RRKyG1 (PHP)