RES: [PHP] Invalid chars in XML
| From: | Alejandro Michelin Salomon | Date: | Tue, 21 Sep 2010 11:34:12 +0000 |
| Subject: | RES: [PHP] Invalid chars in XML | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-308238@lists.php.net to get a copy of this message | ||
Hi
I am working with xml, in portuguese, and i have many problems with special
characters.
I find this code to work with this problem...
When create xml ExpandEntities :
function ExpandEntities( $sText )
{
$trans = array('&' => '&',
"'" => ''',
'"' => '"',
'<' => '<',
'>' => '>' );
return strtr( $sText, $trans );
}
When read xml CompEntities
function CompEntities( $sText )
{
$trans = array('&' => '&',
''' => "'",
'"' => '"',
'<' => '<',
'>' => '>' );
return strtr( $sText, $trans );
}
Alejandro M.S.
-----Mensagem original-----
De: robert mena [mailto:robert.mena@gmail.com]
Enviada em: segunda-feira, 20 de setembro de 2010 17:08
Para: php-general@lists.php.net
Assunto: [PHP] Invalid chars in XML
Hi,
I am trying to parse a XML file with simplexml_load but it gave me error.
While inspecting the contents I found a & inside the value of a tag.
<tag>something & something</tag>.
After I've removed the & everything went fine. So which chars I should not
put in my file? Should I use some conversion function like html_entities?
Does the receiver of the XML has to do anything to convert is back?