PHP DOM DomText vs DomElement处理实体

时间:2011-12-22 16:51:58

标签: php xml dom entities

使用DomElement与DomText时,为什么实体的处理存在差异?

示例代码:

$text = 'this&that or this& that';
$document = new \DOMDocument;

$p1 = $document->createElement('p', $text);
// versus
$p2 = $document->createElement('p');
$p2->appendChild($document->createTextNode($text));

var_dump($p1->nodeValue); // thisthat
var_dump($p2->nodeValue); // this&that or this&that

1 个答案:

答案 0 :(得分:1)

区别在于createElement不接受(重音符号)和标记中的非法字符,如果是这样,将忽略这种字符

相关问题