By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,441 Members | 979 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,441 IT Pros & Developers. It's quick & easy.

Get € past a XML parser

P: n/a
I'm having troubles getting the euro sign through an XML parser.

With the following test code:
<?php
$string = "<root><test>€</test></root>";

$parser = xml_parser_create();
xml_set_character_data_handler( $parser, 'cdata' );
xml_set_element_handler( $parser, 'starthandler', 'endhandler' );

if( !xml_parse( $parser, $string ) ) {
print xml_error_string( xml_get_error_code( $parser ));
}

function cdata( $p, $data ) {
print $data."\n";
}

function starthandler( $p, $tag, $att ) {
// print $tag."\n";
}

function endhandler( $p, $tag ) {
// print $tag."\n";
}
?>

I get the following result for $string
$string = "<root><test>€</test></root>";
?
$string = "<root><test>&#x20AC;</test></root>";
?
$string = "<root><test>&euro;</test></root>";
Undeclared entity error

Any solutions to this problem?

Rutger Claes
--
Rutger Claes rg*@rgc.tld
Replace tld with top level domain of belgium to contact me pgp:0x3B7D6BD6
Do not reply to the from address. It's read by /dev/null and sa-learn only

Jul 17 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a
>> $string = "<root><test>€</test></root>";
It should be
$string = "<root><test>&amp;#8364;</test></root>";

You have to remember to use the translated &amp; in xml for &

HTH
Ron Chaplin
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
T73 Software & Design
www.t73-softdesign.com
To provide custom and quality
software, designs and services,
to our customers, at an affordable rate,
with minimal delay.

Jul 17 '05 #2

P: n/a
Hello,

on 01/07/2005 11:05 AM Rutger Claes said the following:
I'm having troubles getting the euro sign through an XML parser.

With the following test code:
<?php
$string = "<root><test>€</test></root>";


You need to explicitly declare that the output encoding is UTF-8 because
ISO-8859-1 only comprises 8 bit latin characters. Iso-8859-15 would be
the correct encoding but I don't think Expat supports any encoding
besides UTF-8 or ISO-8859-1.

--

Regards,
Manuel Lemos

PHP Classes - Free ready to use OOP components written in PHP
http://www.phpclasses.org/

PHP Reviews - Reviews of PHP books and other products
http://www.phpclasses.org/reviews/

Metastorage - Data object relational mapping layer generator
http://www.meta-language.net/metastorage.html
Jul 17 '05 #3

P: n/a
ro***********@gmail.com wrote:
$string = "<root><test>€</test></root>";
It should be
$string = "<root><test>&amp;#8364;</test></root>";

You have to remember to use the translated &amp; in xml for &

But you don't use entities inside entities I think
HTH
Ron Chaplin
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
T73 Software & Design
www.t73-softdesign.com
To provide custom and quality
software, designs and services,
to our customers, at an affordable rate,
with minimal delay.


--
Rutger Claes rg*@rgc.tld
Replace tld with top level domain of belgium to contact me pgp:0x3B7D6BD6
Do not reply to the from address. It's read by /dev/null and sa-learn only

Jul 17 '05 #4

P: n/a
Manuel Lemos wrote:
Hello,

on 01/07/2005 11:05 AM Rutger Claes said the following:
I'm having troubles getting the euro sign through an XML parser.

With the following test code:
<?php
$string = "<root><test>€</test></root>";


You need to explicitly declare that the output encoding is UTF-8 because
ISO-8859-1 only comprises 8 bit latin characters. Iso-8859-15 would be
the correct encoding but I don't think Expat supports any encoding
besides UTF-8 or ISO-8859-1.


You're right. When I enforce UTF-8 on my xml from the time it get's out of
the DOM Object through the SAX parser and Tidy I get some wrong symbols:
,. But when I tell my browser (Konqueror) to use charset UTF-8, it works.

The problem now is that even though I have a
<meta .... content-type: text/hml; charset=UTF-8" /> and a headers( '...
charset=UTF-8' ) the browser still doesn't pick it up when it is set to
auto charset. I've tried mozilla firefox too, same result.

So now I have a working charset, but nobody will see it. Is there a way to
fix this?

Thanks for the answer,
Rutger Claes
--
Rutger Claes rg*@rgc.tld
Replace tld with top level domain of belgium to contact me pgp:0x3B7D6BD6
Do not reply to the from address. It's read by /dev/null and sa-learn only

Jul 17 '05 #5

P: n/a
Rutger Claes wrote:
Manuel Lemos wrote:
Hello,

on 01/07/2005 11:05 AM Rutger Claes said the following:
I'm having troubles getting the euro sign through an XML parser.

With the following test code:
<?php
$string = "<root><test>€</test></root>";
You need to explicitly declare that the output encoding is UTF-8 because
ISO-8859-1 only comprises 8 bit latin characters. Iso-8859-15 would be
the correct encoding but I don't think Expat supports any encoding
besides UTF-8 or ISO-8859-1.


You're right. When I enforce UTF-8 on my xml from the time it get's out
of the DOM Object through the SAX parser and Tidy I get some wrong
symbols:
,. But when I tell my browser (Konqueror) to use charset UTF-8, it
works.

The problem now is that even though I have a
<meta .... content-type: text/hml; charset=UTF-8" /> and a headers( '...
charset=UTF-8' ) the browser still doesn't pick it up when it is set to
auto charset. I've tried mozilla firefox too, same result.

So now I have a working charset, but nobody will see it. Is there a way
to fix this?


Fixed that too.
It works now!
Thanks for the answer,
Rutger Claes


--
Rutger Claes rg*@rgc.tld
Replace tld with top level domain of belgium to contact me pgp:0x3B7D6BD6
Do not reply to the from address. It's read by /dev/null and sa-learn only

Jul 17 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.