Encoding Problem (UTF-8) in PHP

I want to output the following line in PHP:

ä ö ü ß €

Therefore, I encoded it in utf8 manually:

ä ö ü ß  €

So my script:

<?php
header('content-type: text/html; charset=utf-8');
echo 'ä ö ü ß €';
?>

The first four characters are correct (ä ö ü ß), but unfortunately the “does not match” sign:

ä ö ü ß

Here you can see it.

Can you tell me what I did wrong? My editor (Notepad ++) has settings for encoding (Ansi / UTF-8) and Format (Windows / Unix). Should I change them?

I hope you help me. Thanks in advance!

+5
source share
6 answers

This last character is simply not in the file (try looking at the source), so you cannot see it.

, PHP UTF-8 ( Notepad ++ → UTF-8 ) PHP (.. Notepad ++), Ã . Windows .

+8

Euro (U + 20AC) UTF-8 , . . .

+5

utf8, script :

<?php
header('content-type: text/html; charset=utf-8');
echo "\xc3\xa4"."\xc3\xb6"."\xc3\xbc"."\xc3\x9f"."\xe2\x82\xac";
?>

, php script -utf-8, .

+4

, HTML . HTML- UTF-8, UTF-8. PHP , ; .

, , . - , -. , .

, , ASCII, . . , , .

+2
header('Content-Type: text/html; charset=UTF-8');

, . , . , . UTF-8 , . UTF-8, Latin-1, , , .

I send you to What every programmer absolutely, positively needs to know about encodings and character sets for working with text

0
source

it worked for me

    if (mb_check_encoding($value, 'UTF-8')) {
      return $value = utf8_encode($value);  
    }  
    else  {
      return $value;
    }

Source: https://github.com/jdorn/php-reports/issues/100

0
source

All Articles