php - Why using createElement value doesn't show my input element properly? -


i've following code:

$newdom = new domdocument('1.0', 'utf-8'); $foo = $newdom->createelement('input', 'this value'); $newdom->appendchild($foo); echo $newdom->savehtml(); 

this outputted only: <input>

but when change createelement 'div' works okay

this outputted 'div' or other input:

 <div>this value</div> 

this var_dump($foo):

object(domelement)#5 (17) {   ["tagname"]=>   string(5) "input"   ["schematypeinfo"]=>   null   ["nodename"]=>   string(5) "input"   ["nodevalue"]=>   string(16) "this value"   ["nodetype"]=>   int(1)    ["parentnode"]=>   string(22) "(object value omitted)"   ["childnodes"]=>   string(22) "(object value omitted)"   ["firstchild"]=>   string(22) "(object value omitted)"   ["lastchild"]=>   string(22) "(object value omitted)"   ["previoussibling"]=>   null   ["attributes"]=>   string(22) "(object value omitted)"   ["ownerdocument"]=>   string(22) "(object value omitted)"   ["namespaceuri"]=>   null   ["prefix"]=>   string(0) ""   ["localname"]=>   string(5) "input"   ["baseuri"]=>   null   ["textcontent"]=>   string(16) "this value" } 

the second argument createelement content of tag you're creating. <input> tags can't contain text. need set value attribute. you're trying produce <input value="this value">, not <input>this value</input>.

see createattribute.


Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -