Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 585
nacho10f Avatar asked Dec 17 '25 18:12

nacho10f


2 Answers

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.

like image 146
mario Avatar answered Dec 20 '25 11:12

mario


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.

like image 22
Geoff Adams Avatar answered Dec 20 '25 12:12

Geoff Adams



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!