PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
json_encode doesn't seem to handle zlib encoded data from gzcompress, gzencode, and gzdeflate. It does seem to work with bzcompress data. serialize works. I have included some ways to reproduce the problem below. Same results with version 5.2.0-8+etch10 and 5.2.6-2ubuntu4. Is there something I am missing here or should I submit a bug report?
Json string may not contain arbitrary binary data (see http://json.org for what it may contain). Therefor compliant generator is not required to be able to encode data such as binary streams produced by compression algorithms. You best option, I guess, is to encode binary string into base64 before passing it to json_encode().