php - DOMElement nodeValue inconsistant get vs set -


i have discovered when reading nodevalue domelement returns raw value (i.e. not encoded) when set value must encode first or truncates text @ first invalid entity.

<?php $doc = new domdocument('1.0', 'utf-8'); $element_p = $doc->createelement('p'); // domelement $element_p->nodevalue = 'this & that.'); print($element_p->nodevalue); // 'this '  $element_p->nodevalue = 'this &amp; that.'); print($element_p->nodevalue); // 'this & that.'  // setting truncates text! $element_p->nodevalue = $element_p->nodevalue; print($element_p->nodevalue); // 'this '  // encode before setting, don't decode after getting $element_p->nodevalue = htmlspecialchars('this & that.'); print($element_p->nodevalue); // 'this & that.'  // using htmlspecialchars() preserves original text $element_p->nodevalue = htmlspecialchars($element_p->nodevalue); print($element_p->nodevalue); // 'this & that.' 

is expected behaviour? because surprised me when discovered it!


Comments

Popular posts from this blog

facebook - android ACTION_SEND to share with specific application only -

python - Creating a new virtualenv gives a permissions error -

javascript - cocos2d-js draw circle not instantly -