Reputation: 545
I'm parsing an xml document using php.
When I see the result in my browser I get the following characters:
ñ instead of spanish ñ
à instead of í
á instead of á
ó instead of ó
é instead of é
I was going to use a str_replace and replace every odd character for the good ones, but sadly the pattern before happens only sometimes and in general I have a wide collection of odd characters :(
The xml heading is:
<?xml version="1.0" encoding="iso-8859-1"?>
But if I change it to utf-8 it simply won't be printed ..
I load the xml as a string with simplexml_load_string (comes from database like that)
Can you please give me any ideas on how to solve this?
Thanks a lot
Upvotes: 2
Views: 1293
Reputation: 381
// new xml
$xml = new SimpleXMLElement('new.xml');
// Displaying XML in textual form
echo $xml->asXML();
Upvotes: 0
Reputation: 2535
You have 2 options:
a) include a header('Content-Type: text/html; charset=iso-8859-1');
before any output in your php file.
b) convert the output to utf-8 with $str = mb_convert_encoding($str, 'UTF-8', 'ISO-8859-1');
Both should do the trick.
Upvotes: 2
Reputation: 2113
$string = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $string);
Upvotes: 0
Reputation: 125
SimpleXML
uses UTF-8 to encode stored strings. You can use an XML-File with iso-8859-1, but if you want to print XML values with this encoding, you have to use utf8_decode
before.
Upvotes: 0