About php.ini open zlib compression output causes garbled problem
If you now have a PHP script like this:
Normally, running this script is no problem, the results are displayed in Google Chrome:
But if you modify the php.ini configuration file, turn the zlib compression output on:
Change the configuration option in the red box above to on, then save restart Apache, then run the script just now, there will be garbled situation:
Why is that? Let's try modifying the PHP script to comment out the Echo statement:
Then run the script, you can see why it is garbled, because the php.ini configuration file on the premise of zlib compression output, the direct use of Ob_clean () will cause the program to the browser output a strange character:
Change IE try, the result is the same, but the style of special characters changed:
The same problem exists on Linux, proving it's not a problem with windows, so how do you get rid of this special character? As simple as using Ob_start () before using Ob_clean (), we can:
add Ob_start (), the back of the Hello world can be displayed normally, will not garbled.
So now we can draw a conclusion: If you call Ob_clean () directly in a PHP script, At the same time the server php.ini turned on the zlib compression output, it will cause the contents of the output after all garbled, at this point, or you will zlib compressed output off, or in the Ob_clean () before adding Ob_start (), or can not solve the problem. However, given that the program apes do not normally modify the server configuration permissions, it is important to call Ob_start () before using Ob_clean () in coding.
Finally, as to why the zlib compression output is turned on, the direct call to Ob_clean () will cause the program to output a special character resulting in garbled characters, and after the call will be OK, this problem still need to study, or have any PHP God can tell the reason?