PHP Internationalization and Localization
Setting the Character Encoding of Outgoing Data
Problem
You want to make sure that browsers correctly handle the UTF-8–encoded text that your programs emit.
Solution
Set PHP’s default_encoding configuration directive to utf-8. This ensures that the Content-Type header PHP emits on HTML responses includes the charset=utf-8 piece, which tells web browsers to interpret the page contents as UTF-8 encoded.
Discussion
Setting default_encoding gives web browsers a heads-up that your page contents should be interpreted as UTF-8 encoded. However, you still have the responsibility of making sure that the page contents really are properly UTF-8 encoded by using string functions appropriately. Details how to do that.
If you can’t change the default_encoding configuration directive, send the proper Content-Type header yourself with the header() function.
Example Setting character encoding
header('Content-Type: text/html;charset=utf-8');
No comments:
Post a Comment