PHP DOM DomText 与 DomElement 实体处理
为什么使用 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
Why is there a difference in treatment of entities when using DomElement versus DomText?
example code:
$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
不同之处在于
createElement
不接受标记中的(重音符号)和非法字符,如果是,将忽略这种字符the difference is that the
createElement
does not accept (accents) and illegal characters in markup and if so, will ignore this kind of character