Reputation: 3103
So I came across this bit of php code:
<?php
$long_url = "http://example.com";
$bit_ly = "http://api.bit.ly/v3/shorten?login=your_user_name&apiKey=R_4868094cb43d09fb&longUrl=" . $long_url . "&format=json";
$response = json_decode(file_get_contents($bit_ly));
$short_url = $response->data->url;
?>
I tested this locally and it worked great, once I uploaded it onto my server, I noticed iI was getting some errors, come to find out, jason_decode became standard from PHP 5.2 and my server is running PHP 4 and does not work.
Is there a simple way, without compiling a new version of PHP or adding a library to get this to work with PHP 4?
Thanks for the help!
Upvotes: 1
Views: 6286
Reputation: 16610
The best two json_decode() and json_encode() implementation you'll ever find for PHP4 with elegant degradation when your script is used with PHP5:
http://www.abeautifulsite.net/blog/2008/05/using-json-encode-and-json-decode-in-php4/ (also read the comments)
and this (same with a few twists): http://www.epigroove.com/posts/97/how_to_use_json_in_php_4_or_php_51x
Upvotes: 0
Reputation: 7961
Yep.
Check out the json website.
You could use the PECL json package
Or if you are using codeigniter
Upvotes: 1
Reputation: 28765
Checkout this this article, probably this can help you
http://blueberryware.net/2008/10/28/php4-json-encode-decode
http://www.epigroove.com/posts/97/how_to_use_json_in_php_4_or_php_51x
Upvotes: 1