Re.: simplexml_load_file parser error with ampersands in urls
| From: | Jānis Elmeris | Date: | Mon, 06 Jun 2022 09:19:51 +0000 |
| Subject: | Re.: simplexml_load_file parser error with ampersands in urls | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-328004@lists.php.net to get a copy of this message | ||
Yes, an unescaped ampersand is not allowed in XML, including the attributes.. See the exaplanation
and examples here: https://www.w3resource.com/xml/prohibited-character-literals.php
You can also use XML validation tools to see if your sample XMLs are valid, e.g.: https://www.xmlvalidation.com/
Regards,
Janis
________________________________
No: Dennis Nezic <dennisn@dennisn.mooo.com>
Nosūtīts: svētdiena, 2022. gada 5. jūnijs 04:52
Kam: php-general@lists.php.net <php-general@lists.php.net>
Tēma: simplexml_load_file parser error with ampersands in urls
If there are ampersands (&) in links within tags (eg. href= url=
rel=) simplexml_load_file() fails with
parser error : EntityRef: expecting ';'
This useful comment in the manual suggests str_replace()'ing it with
the & entity:
https://www.php.net/manual/en/function.simplexml-load-file.php#117566
%26 url encoding also works, although no other character that
I'm aware of seems to cause this parser error / requires
urlencode()'ing.
But this seems like a bug, or something that simplexml_load_file should
be able to handle? Or does xml or something not allow &'s in tag
properties?
For example, trying to load this file:
<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<entry>
<link href="http://example.com/bla.php?yes&no"
/>
</entry>
</feed>