note 94391 deleted from simplexmlelement.xpath by danbrown
| From: | danbrown@php.net | Date: | Mon, 02 Nov 2009 15:28:04 +0000 |
| Subject: | note 94391 deleted from simplexmlelement.xpath by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-162331@lists.php.net to get a copy of this message | ||
Note Submitter: robeddielee at hotmail dot com
----
Regarding the problem described by paul at pmtlogic dot com about single quotes:
His query code...
<?php
// ...
$result = $xml->xpath("//zone[@country='Cote d\'Ivoire']");
// ...
?>
...is incorrect. In double-quoted strings in PHP, to insert a backslash, you need to double it.
There is no need to escape single quotes in double-quoted things. His code should have read...
<?php
// ...
$result = $xml->xpath("//zone[@country='Cote d\\'Ivoire']");
// ...
?>
...which may have had a better change of working correctly (we want one backslash to be sent to the
xpath interpreter to escape the single quote).
His original code would have silently dropped the superfluous backslash character at the PHP level,
resulting in an un-escaped single quote within a single-quoted string at the xpath level.