2

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?

0

5 Answers 5

4

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

Sign up to request clarification or add additional context in comments.

Comments

2

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.

Comments

2

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

Comments

0

Take a look at this tutorial: http://www.epigroove.com/posts/97/how_to_use_json_in_php_4_or_php_51x.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.