: Encoding fails whatever I try I am trying to set my site's encoding to UTF-8 but I fail. Environment: Ubuntu Desktop 13.04, Apache 2.2, PHP+FPM. Added a .htacces: AddDefaultCharset UTF-8 Meta:
I am trying to set my site's encoding to UTF-8 but I fail. Environment: Ubuntu Desktop 13.04, Apache 2.2, PHP+FPM.
Added a .htacces:
AddDefaultCharset UTF-8
Meta:
file -bi * output:
inode/directory; charset=binary
inode/directory; charset=binary
text/html; charset=utf-8
inode/directory; charset=binary
inode/directory; charset=binary
text/x-php; charset=utf-8
inode/directory; charset=binary
text/x-php; charset=us-ascii
inode/directory; charset=binary
text/x-php; charset=us-ascii
(similar in subdirectories)
System encoding is also UTF-8.
PHP header:
header("Content-Type:text/html;charset=UTF-8");
The problem itself:
When I echo accent letters like this: echo "ÁÁÁn"; it prints out them well. But when I send these letters through a post form, they become these: �
Maybe my browsers encoding messes up everything? I really hope no, because everything is on default. Anyway, w3c validator says it is a valid HTML5 UTF-8 encoded page.
A hope anyone can help me. Thanks in advance.
More posts by @Phylliss660
1 Comments
Sorted by latest first Latest Oldest Best
From: allseeing-i.com/How-to-setup-your-PHP-site-to-use-UTF8
Unicode is not quite a first class citizen in PHP, so you'll have to do some tweaking to get it to grok UTF-8.
Firstly, you need to ensure that you have MBString enabled in your copy of PHP. If you're on Linux and using a packaged PHP, it may be installed by default. If not, it's probably just a case of adding it with:
$ yum install php-mbstring
...
Assuming you have multi-byte support built-in, now you need to make sure PHP knows that you want to handle text as UTF-8 internally. Add the following to an include that gets parsed before anything else, and you should be good to go:
//setup php for working with Unicode data
mb_internal_encoding('UTF-8');
mb_http_output('UTF-8');
mb_http_input('UTF-8');
mb_language('uni');
mb_regex_encoding('UTF-8');
ob_start('mb_output_handler');
If you're doing anything with strings other than reading them from a database and outputing them, you'll probably want to read about PHP's multi-byte functions. Basically, many string functions have multi-byte capable alternatives, with the prefix 'mb_'. So, substr() becomes mb_substr()
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.