note 104637 deleted from class.domnode by danbrown
| From: | danbrown@php.net | Date: | Mon, 27 Jun 2011 16:03:04 +0000 |
| Subject: | note 104637 deleted from class.domnode by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-181000@lists.php.net to get a copy of this message | ||
Note Submitter: magilvia
----
It says that nodeValue uses UTF-8 encoding. But this is not true. Try this code:
<?
$DOM = new DOMDocument('1.0', "UTF-8");
$DOM->loadHTML(utf8_encode("<p>-’-</p>"));
echo $DOM->saveXML() . PHP_EOL;
$node = $DOM->getElementsByTagName("p")->item(0)->childNodes->item(0); // Text
node inside p tag
echo $node->nodeValue . PHP_EOL;
echo utf8_decode($node->nodeValue) . PHP_EOL;
?>
It will output :
<?xml version="1.0" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><body><p>-‘-</p></body></html>
-ââ¬Ë-
-?-
The character ’ is correctly loaded into the DOM document since it's translated
correctly into ‘ but the nodeValue property uses a weird encoding (ââ¬Ë) which
utf8_decode does not recognise at all (outputting a ?)
I need to find the real internal encoding of nodeValue to manipulate correctly the content.
Any help appreciated.