Special characters from xml file are not displayed correctly using php

It may be a stupid question, but it is not a question of what I can find, it is a question that I do not know what to look for. There are some special characters that do not display correctly in php. I take some information from an XML file and repeat it.

those.:

should be → Nuremberg

echo → Nürnberg

any advice on what to look for or how to resolve it?

+1
source share
6 answers
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
+1
source

try using a different character set on the page that you echo from

http://www.w3schools.com/tags/ref_charactersets.asp

0
source

Can you try the following meta tag in your head HTML.

 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> 
0
source

"I take some information from the xml file and repeat it."

The Windows command line does not support utf8 as it does not use the UTF8 font.

Just put the file in a place accessible through the web server and test it by calling the file through the web server. Alternatively, output the script output to a text file:

php test.php> output.txt

And either open output.txt is an editor that supports UTF8, or uses a Tail program that supports utf8.

test.php

 <?php echo "Nürnberg"; ?> 

Run from the command line:

 php test.php Nürnberg 

Call via web server http: //localhost/test.php

 Nürnberg 
0
source

There is a mismatch between the character encoding of your XML and what you output from PHP. Most likely, one of them is UTF-8, and one is ISO-8859.

On the PHP side, you can set this using the header directive

 <?php header('Content-Type: text/plain; charset=ISO-8859-1'); header('Content-Type: text/plain; charset=utf-8'); ?> 

and / or in the output HTML

 <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 

On the XML side, most quality text editors allow you to specify the character encoding when saving the file. (E.g. WordWrangler on Mac)

If the XML file is indeed located in ISO-8859, you can use utf8_encode() to convert it to UTF-8 as it reads to.

Deep discussion of PHP and character encodings .

0
source

All Articles