0

I have an xml file which contents special character like

<string>Jüri (Yuri)</string>

and when I am pass this xml through xml_parse() it returns false, I am geting the value from database, how can I overcome this?

hakre
  • 193,403
  • 52
  • 435
  • 836
Bidyut
  • 539
  • 2
  • 8
  • 17
  • Provide a [hex-dump of the string](http://stackoverflow.com/q/1057572/367456) and the code is missing where you get that error. And please create a 3-6 line PHP code example from scratch that demonstrates that function returning FALSE with your data as string (no database interaction). Stackoverflow requires that you provide a self-containing, non-live-code example when you ask a question. So please provide it. – hakre Oct 16 '13 at 06:42
  • Also [according to the documentation](http://php.net/xml_parse) that function does not return `FALSE`, it returns either `1` or `0`. In case of `0` there are more functions you need to call to learn about the cause of the error. You didn't provide that information so far. So -1 for not providing enough information and showing no efforts to actually learn about your own question. – hakre Oct 16 '13 at 06:44

3 Answers3

1

Either initialize the XML parser with the correct encoding, or specify the encoding within the XML file itself.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
  • Initializing the parser with the correct input encoding is only possible in (very) outdated PHP versions. According to the question, the encoding of the XML is UTF-8 which is automatically supported by the XML parser as it is correctly specified with the XML. – hakre Oct 16 '13 at 07:24
  • if I am using xml_parser_create("ISO-8859-1") is not working but if using then working, I mean returns 1 – Bidyut Oct 16 '13 at 07:38
  • You'll need to look at the bytes used for the text in order to see if ISO 8859-1 is the correct encoding. – Ignacio Vazquez-Abrams Oct 16 '13 at 07:46
1

Specify the encoding type properly on your XML content. Something like this will do

<?xml version="1.0" encoding="utf-8"?>

or

 <?xml version="1.0" encoding="ISO-8859-1" ?> 
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
  • The encoding type *is* properly specified in the XML provided in the question. See http://www.w3.org/TR/xml/#charencoding – hakre Oct 16 '13 at 06:49
0

You can try wrapping the data with CDATA tags.

<string><![CDATA[Jüri (Yuri)]]></string>
Steven
  • 1,564
  • 1
  • 22
  • 34