看板 PHP 關於我們 聯絡資訊
<? $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)