In the "PHP Cookbook", they say (p.589) that to properly set the character encoding of outgoing data to UTF-8, it is necessary to edit the default_encoding configuration to utf-8. Show However, I cannot find this configuration in file php.ini. Should I simply add a line that would say
I do have a ;default_charset = "iso-8859-1". As you can see ( I also found other encoding directives that I don't know what to do about:
Is there any reason why I shouldn't simply replace them all with
asked Feb 19, 2012 at 18:02
1 You should set your
(PHP Cookbook may have a typo in it if they ask you to
change the You'll also want to make sure that your web server is set to output UTF-8 if you're going to outputting UTF-8 encoded characters. In Apache, this can be set by in the httpd.conf file:
As for modifying the
answered Feb 19, 2012 at 18:38
Ben DBen D 13.8k3 gold badges44 silver badges59 bronze badges 6 Modify the line
to read
About the other options, do not touch them. Avoid default settings, always explicitly set the encoding of in everything you do
Also, beware of the encoding in which your PHP files are saved, make sure that they are in UTF-8, especially if they contain strings to be displayed or compared.
answered Feb 19, 2012 at 18:36
gioelegioele 9,1615 gold badges52 silver badges77 bronze badges I had a problem on my MySQL query that it would not recognize some Latin accentuation, so the query would fail. I thought it could be the PHP file and so on, till I found out that using PDO to call the MySQL function I had to add the character set. The weird thing is that on the previous server I used it worked fine!
answered Oct 29, 2013 at 23:31
MiguelMiguel 3,0532 gold badges29 silver badges28 bronze badges 2 At the htaccess level (.htaccess file), the PHP directive should be
answered Nov 11, 2017 at 20:45
ontananzaontananza 3124 silver badges6 bronze badges To resolve it, I changed "UTF-8" to "UTF-8" (without the dash), solving the problem instead. It was on CentOS.
answered Nov 30, 2016 at 17:44
1 Not the answer you're looking for? Browse other questions tagged php unicode encoding character-encoding or ask your own question.Does PHP use UTFPHP | utf8_encode() Function
The 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.
What is the default character set for PHP?There is a character encoding setting inside of your php. ini file. By default, this is set to the standard Latin encoding (ISO-8859).
Is UTFFortunately UTF-8 is the default per sé. When reading an XML document and writing it in another encoding, mostly this attribute will be patched too.
What is UTFDefinition and Usage. The utf8_encode() function encodes an ISO-8859-1 string to UTF-8. Unicode is a universal standard, and has been developed to describe all possible characters of all languages plus a lot of symbols with one unique number for each character/symbol.
|