开发者

php 5.1.6 json_encode and codeigniter

Im building a codeigniter app which uses json_encode to开发者_高级运维 provide ajax data in many places... today I learned that the server has php 5.1.6 which doesnt support this method (or json_decode).. what can I do?? please help.


There is an emulation of json_encode() in upgradephp. Just include() that script, and you don't need to rewrite anything.
As alternative you can use PEAR::PHP_Compat. IIRC it has an emulation of that too.
(There are further alternative implementation floating around; but often object-style and not as fast and designed to emulate the core function.)

You can set them up with auto_prepend_file= even. If you just want the JSON extension enabled, there are other sources of course.


You could use Services_JSON if CodeIgniter can use it instead of PHP 5.2's json_* functions - I know Zend_Framework has Zend_Json which uses json_* functions if available, otherwise it uses its own implementation in userland PHP code as a fallback.

Of course, if you have access to the server to compile PHP, you could try the extension or upgrading to PHP 5.2 (a better solution).

EDIT: I would take the route of compatibility layers as mentioned above.


The json_decode is added since (PHP 5 >= 5.2.0, PECL json >= 1.2.0), it is supported in your version too, you should give it a try :)


I needed json_encode and json_decode for jquery grid. I tried upgradephp but json_encode didnt seem to work with jquery grid so I deleted that function from the file and added this one. json_decode seems to work just fine though.


In fact, 5.1.6 supports json_decode and json_encode, but they can be a bit weird. As in, if you feed it invalid JSON, such as if you have a blank key, it will die without any warnings or errors. But I use json_encode and json_decode every day in a 5.1.6 environment. It's totally possible.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜