First of all, to not be confused by encodings problem, you really want to read the following article: http://kunststube.net/encoding/
Second, I just have done the following:
$ vim ~/sandbox/php/encoding.php
( inserted your code verbatim )
$ cd ~/sandbox/php/
$ php -S localhost:1200
After I opened in Firefox the page http://localhost:1200, I got the contents of $String
as they are.
I mean that I got the following line of chars:
à¸?่à¸à¸•ั้งเมื่à¸
This means your browser, whichever it is, does not know how to render the characters you are entering to it. The string itself is being encoded in UTF-8 correctly. You have to set your browser to show the text as UTF-8, or probably install the fonts which support those symbols.
Also, if you want to output, say some text with UTF-8 Devanagari symbols, you just need to satisfy the following requirements in PHP:
- Your source code file must be saved in UTF-8.
- You must send the utf-8 charset subheader, which you already do.
- You must put the string you want to output to the browser verbatim to the source code, no need to encode it in any way, PHP does not care.