473,320 Members | 2,048 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Get € past a XML parser

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
5 4955
>> $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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: wenke | last post by:
Hi, I am using the following code (see below) from php.net (http://www.php.net/manual/en/ref.xml.php, example 1) to parse an XML file (encoded in UTF-8). I changed the code slightly so that the...
6
by: J. Baute | last post by:
I'm doing some tests to see if the Session.LCID can be used to easily change a user-dependant locale for number & date/time formatting in ASP. As far as I get the theory this should work, but I'm...
1
by: Marco W | last post by:
Hi, <xsl:value-of select="translate(current(),'€','EUR')" /> only replace the euro sign with 'E' and not 'EUR'. How can I replace the euro sign in the string 'EUR'?
5
by: Lars | last post by:
Why doesn't the W3C's HTML Validator recognize &euro; and what do I have to do to make my html-file valid?
8
by: Kim Bundgaard | last post by:
Hi Anyone know where I can look for problem with codepage conversion between DB2 UDB Connect EE V8.2 (fixpak 3) and DB2 UDB z/OS V7. With DB2 UDB Connect EE V7.2 (fixpak 7) i get Ebcdic X'5A'...
4
by: Cadderly | last post by:
Hi all, I have the following pseudo-c-code which parse a command line, and puts the command and its arguments in an array, and I can't figure out where/how I should use free: main(void):...
1
by: geoffblanduk_nospam | last post by:
Does anyone know of any classes that will load the XML documentation into some useful classes? I'm assuming there must be some somewhere as that's what the Object browser does to show summaries...
1
by: Agnes | last post by:
it is very strange that " i place some code in my Page1's textbox validated event'. then I cut the textbox and paste into page2. I found that , the validated event is change. From Private Sub...
2
by: Agnes | last post by:
In my form, i got around 20 textbox and buttons, Now,i need to move them into the group box. I use 'copy & paste' after doing that, I found that the handles "button.clicked, checkbox.checked'.....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.