php non-english character using $echo

Go To StackoverFlow.com

2

in Php, I want to print Düsseldorf using

 echo 'Düsseldorf'; 

However it turns out to be something like this D�sseldorf

Please suggest what should I do to print european characters mostly non-english.

2012-04-04 23:36
by Mas


1

If you are able to specify it as a constant, do the following.

$echo 'Düsseldorf';

For further information refer to the chart here: http://www.ascii.cl/htmlcodes.htm

Every character that's printable has a corresponding HTML entity.

2012-04-04 23:39
by Jay Croghan
That's possible but not really a good way for that. First you could better use ü (for ü, ö for ö and so on) but its easier to change the encodin - Dion 2012-04-04 23:45
No it's not easier to change the encoding, based upon the users local encoding it may not be supported. Encoding should not matter, data and design separate, means it should work in any environment with any backend, not cross your fingers and hope the encoding is compatible - Jay Croghan 2012-04-04 23:57


5

The PHP, File and HTML encoding should be the same.

For PHP:

<?php header('Content-Type: text/html; charset=utf-8'); ?>

Check the encoding of your text editor.

For HTML:

<meta charset=utf-8>

The quick and dirty way:

echo 'D&uuml;sseldorf ist eine sch&oouml;ne Stadt!';
// Düsseldorf ist eine schöne Stadt!
2012-04-04 23:38
by binarious
Or iso-8859-1 encodin - Dion 2012-04-04 23:43
Yes, but I would always recommend utf-8. It's more common, even in Germany - binarious 2012-04-04 23:44
I am from Germany too^^ actually I thought ISO-8859-1 is more common here but I often also use UTF-8.. - Dion 2012-04-04 23:46
It was I think :). php 5.4's default charset is utf-8, therefore we should go with them - binarious 2012-04-04 23:47
Ads