What extensions would you recommend and how should php be best configured to create a website that uses utf-8 encoding for everything. eg...
It seems that php does not really cope well with multibyte character sets at the moment. So far I have worked out that mbstring looks like an important extension.
Is it worth the hassle..?
PHP | utf8_encode() FunctionThe utf8_encode() function is an inbuilt function in PHP which is used to encode an ISO-8859-1 string to UTF-8. Unicode has been developed to describe all possible characters of all languages and includes a lot of symbols with one unique number for each symbol/character.
The difference between utf8 and utf8mb4 is that the former can only store 3 byte characters, while the latter can store 4 byte characters. In Unicode terms, utf8 can only store characters in the Basic Multilingual Plane, while utf8mb4 can store any Unicode character.
To change the character set encoding to UTF-8 for the database itself, type the following command at the mysql> prompt. Replace dbname with the database name: Copy ALTER DATABASE dbname CHARACTER SET utf8 COLLATE utf8_general_ci; To exit the mysql program, type \q at the mysql> prompt.
The supposed issues of PHP with Unicode content have been somewhat overstated. I've been doing multilingual websites since 1998 and never knew there might be an issue until I've read about it somewhere - many years and websites later.
This works just fine for me:
Apache configuration (in httpd.conf or .htaccess)
AddDefaultCharset utf-8
PHP (in php.ini)
default_charset = "utf-8"
mbstring.internal_encoding=utf-8
mbstring.http_output=UTF-8
mbstring.encoding_translation=On
mbstring.func_overload=6
MySQL
CREATE
your database with an utf8_*
collation,
let the tables inherit the database collation and
start every connection with "SET NAMES utf8"
HTML (in HEAD element)
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With