• json_encode and json_decode that works in PHP4 and PHP5
by Stanley, January 15, 2009
Last night, I spent 2 hours overhauling a snippet of code in my WordPress plugin. My plugin uses PHP5’s json_encode and json_decode functions but a lot of users have been complaining of problems. The biggest cause is the servers their on are using PHP4 instead of the latest PHP5 installation. Some users managed to workaround the problem with their web hosting companies by upgrading to PHP5. Some, unfortunately, are either too technically challenge to even know what PHP is. Or their hosting platform simply won’t do PHP5, for whatever reasons. Anyway, after researching for about an hour, I decided to go with the solution mentioned here:
http://my.php.net/manual/en/function.json-decode.php#80606
It checks if json_encode and json_decode funtions are available. If its available, the server has to be PHP5 and above. If not it turns to a JSON manipulation library to implement the encoding and decoding functionality.
Turns out to be a pretty simple solution after all. I was able to make the necessary changes to my code within 15 mins.










Featured
Recent Comments

Blogroll
Categories