PHP 5 DOM, XPath, UTF-8, and Form Input

From: Date: Sat, 19 Mar 2005 15:42:21 +0000
Subject: PHP 5 DOM, XPath, UTF-8, and Form Input
Groups: php.general 
Request: Send a blank email to php-general+get-211101@lists.php.net to get a copy of this message
I have been doing some testing and need confirmation that the following is correct. You have a DOMDocument that potentially contains UTF-8 encoded data (it might not however). You want to search it via DOMXpath->query() using a value that comes from a $_POST value. If the page that posts the data via a form to the search script IS NOT encoded in UTF-8, then the value must be converted to UTF-8 before it is used in the query expression. Else, if the posting page IS UTF-8 encoded, then the $_POST data does not need to be converted before being used in the expression. Is this correct? Also, if the $_POST data comes from a UTF-8 encoded page, and it needs to be sanitized before use, will the basic PHP string functions work on the data (e.g. htmlentities, stripslashes, trim, preg_replace, etc)? If not what do I have to do?

« previous php.general (#211101) next »