note 104637 added to class.domnode
| From: | magilvia at osu1 dot php dot net | Date: | Mon, 27 Jun 2011 15:41:54 +0000 |
| Subject: | note 104637 added to class.domnode | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-180999@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 69.147.83.197
Probable Submitter: 151.31.80.210
----
Manual Page -- http://www.php.net/manual/en/class.domnode.php
Edit -- https://master.php.net/note/edit/104637
Del: integrated -- https://master.php.net/note/delete/104637/integrated
Del: useless -- https://master.php.net/note/delete/104637/useless
Del: bad code -- https://master.php.net/note/delete/104637/bad+code
Del: spam -- https://master.php.net/note/delete/104637/spam
Del: non-english -- https://master.php.net/note/delete/104637/non-english
Del: in docs -- https://master.php.net/note/delete/104637/in+docs
Del: other reasons-- https://master.php.net/note/delete/104637
Reject -- https://master.php.net/note/reject/104637
Search -- https://master.php.net/manage/user-notes.php