Reputation: 1663
I've just bought a hosting on a server which runs with PHP 5.1.6. Earlier, I've prepared a website which uses a lots of json_encode
and json_decode
calls.
As I've find it out now, those PHP functions are available in PHP 5 >= 5.2.0
It's a simple hosting, so I'm unable to add PECL extensions and so on. I'm wondering if there is such a solution written in PHP, which will allow me to convert PHP variable into JSON strings and backwards. Do You know any?
Upvotes: 2
Views: 7191
Reputation: 1985
I use this http://pear.php.net/pepr/pepr-proposal-show.php?id=198 then create a wrapper, detect your php version is smaller than 5.2 map json_encode to encode and json_decode to decode
Upvotes: 2
Reputation: 915
The PHP.net manual page for json_encode/decode have a large number of examples of replacement functions for users of lower versions of PHP.
http://php.net/manual/en/function.json-encode.php
http://php.net/manual/en/function.json-decode.php
Upvotes: 4
Reputation: 490647
How to use JSON in PHP 4 or PHP 5.1.x
You basically check to ensure the native functions exist or not, and if they don't, you redefine them with the external parsing code.
Upvotes: 0
Reputation: 24989
Take a look at this tutorial: http://www.epigroove.com/posts/97/how_to_use_json_in_php_4_or_php_51x.
Upvotes: 0
Reputation: 272416
Go to json.org, scroll down to the bottom of the page and have a look at the libraries available for various languages, including PHP.
Upvotes: 2