About php.ini open zlib compression output causes garbled problems

Source: Internet
Author: User
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?




  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.