Question

I am using UTF8 encoding without BOM for all my php scripts for years, and they work fine. Today i discovered that thereis core directive named zend.multibyte, and it is zero (disabled) by default.

So, if it does not affect scripts parsing.. what exactly does it affect?

Was it helpful?

Solution

Zend Multibyte is needed for ASCII-incompatible encodings, like some Asian encodings from pre-unicode/pre-utf-8 times and is mostly used in Japan. when enabled the parser will check mbstring.script_encoding and use that encoding while parsing. As internally some conversions happen this should be avoided, but for some users is the only way they can use PHP.

OTHER TIPS

The point of it is to affect script parsing. As johannes stated one purpose is for encodings that are incompatible with ASCII. (UTF-8 is compatible with ASCII, that's why you don't need it.)

But it can also be used to transparently convert script encodings at compile time. Say for some reason your text editor can only save as ANSI but you need your code to see UTF-8. Turning on zend.multibyte and declaring your scripts' encoding as Windows-1252 will let you encode your scripts as ANSI, and PHP will transparently convert the string literals contained with them from ANSI to the encoding set in php.ini's internal_encoding directive (the default is UTF-8). Since this happens at compile time, to your code, your scripts will all contain UTF-8.

You can declare your scripts' encoding two ways.

  1. By setting the zend.script_encoding directive in php.ini
  2. By adding declare(encoding=...); at the top of each of your PHP files.

From php.ini:

; If enabled, scripts may be written in encodings that are incompatible with
; the scanner.  CP936, Big5, CP949 and Shift_JIS are the examples of such
; encodings.  To use this feature, mbstring extension must be enabled.
; Default: Off
;zend.multibyte = Off

; Allows to set the default encoding for the scripts.  This value will be used
; unless "declare(encoding=...)" directive appears at the top of the script.
; Only affects if zend.multibyte is set.
; Default: ""
;zend.script_encoding =
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top