2011-11-13 10 views
0
$new = $doc->createElement("Cars"); 

要素を開くにはどうすればこの要素を閉じることができますか?XMLとPHPに関する質問

と私は、テキストボックスを持っている場合

<input type="text" name="toCity"> 

どのように私は、ユーザーが要素としてテキストボックスに置くものを書くことができますか?

ご協力いただければ幸いです。

答えて

0

このライン:

$new = $doc->createElement("Cars"); 

はちょうど開いたタグが、全体の要素を作成しないでください。これは、あなたが車に要素を追加していない場合、それはようである空のタグになることを意味します

<cars /> 

そうでない場合、あなたはappendChild()メソッドを使用して要素を追加することができ、それは次のようになります。

とにかく
<cars> 
    // other elements here 
</cars> 

あなたはこのコードを使用することができますテキストエリア内のテキストを追加するには:

$doc = new DOMDocument(); 
$doc->formatOutput=true; 
$textarea = $doc->createElement("textarea"); 
$text = $doc->createTextNode("The text I like"); 
$textarea->appendChild($text); 
$doc->appendChild($textarea); 
+0

TYとどのように私はそれに要素を追加しますが – suffix

+0

OKこのコードを使用しています – suffix

+0

'code' <?php $ doc = new DOMDoucment(); $ doc-> formatOutput = true; $ new = $ doc-> createElement( "Employees"); $ doc-> appendChild($ new); \ $ b = $ doc-> createElement( "employee"); ? $ DOC->は > 'code' いただきました!そのコードと間違って( "wrote.xml")セーブ: – suffix