8

If I were to write a new php file, and include echo "current mb_internal_encoding: ".mb_internal_encoding() , where would the output value come from? How is it "decided" / how is it governed?

Background: I wrote a web app where I thought I had done everything to set the whole site to utf-8 and found that I still needed to set this value manually...

JDelage
  • 13,036
  • 23
  • 78
  • 112

1 Answers1

7

It depends on the setting of mbstring.internal_encoding in php.ini.

deceze
  • 510,633
  • 85
  • 743
  • 889
  • 1
    Interesting. I have `;mbstring.internal_encoding = EUC-JP` so it's not active. Also I find `;mbstring.language = Japanese`, `;mbstring.http_output = SJIS` . I'm developing using the WAMPserver stack, I have no idea why all those are set to Jpz charsets. Any reason why I shouldn't go through the entire php.ini and replace any mention of any charset with `'utf-8'`? – JDelage Feb 24 '12 at 03:27
  • 1
    Jup, for some reason PHP likes ISO-8859 as default. You should handle these settings in your application to keep it portable. Changing the php.ini everywhere you want to deploy your app is often not the most convenient solution. – deceze Feb 24 '12 at 03:48
  • Hmmm.... I tried `mbstring.internal_encoding = UTF-8`, `"UTF-8"`, `utf-8` and then `"utf-8"`, and I still get ISO-8859 when I run `echo "current mb_internal_encoding: ".mb_internal_encoding()`. Any idea what I'm doing wrong? – JDelage Feb 24 '12 at 04:20
  • Please see my other questions http://stackoverflow.com/questions/9446473/why-is-my-internal-encoding-iso-8859-1-when-i-have-specified-utf-8-in-my-php-ini and http://stackoverflow.com/questions/9446832/wampserver-why-is-the-stack-installed-with-2-php-ini-files explaining my problem above: I was modifying the wrong `php.ini` file... – JDelage Feb 25 '12 at 18:55
  • 3
    As of 5.6, it's deprecated and the default value is set by default_charset, which itself is [UTF-8 by default](http://php.net/manual/en/ini.core.php#ini.default-charset). – GreenReaper Sep 22 '14 at 14:19
  • @GreenReaper this is not true. In PHP 5.6.38 I have `default_charset=windows-1251`, however default value of `mb_internal_encoding()` is UTF8. – The Godfather Dec 11 '18 at 20:21
  • @TheGodfather Perhaps the documentation is wrong? Or you need to put it in quotes? Per http://php.net/manual/en/mbstring.configuration.php#ini.mbstring.internal-encoding it should still be overridable there, since deprecated doesn't mean removed (yet). – GreenReaper Dec 13 '18 at 18:09