1

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!

1
  • If your server is running PHP4, something is wrong. Please speak to your sysadmin about the issue. PHP4 is no longer supported and has not been updated for years. You should not be using it. Commented Apr 2, 2011 at 5:38

3 Answers 3

1

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

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

1 Comment

thanks for the links!, I ended up using the 1st link to get it to work!
1

Yep.

Check out the json website.

You could use the PECL json package

Or Blueberryware

Or if you are using codeigniter

2 Comments

What if the PHP version is lower than 4.3.0?
@Maxbester Then it's time to find a new webhost (php 4.3.0 was released at the end of 2002)
0

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

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.