PHP 4 和 json_decode
所以我遇到了这段php代码:
<?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;
?>
我在本地测试了它,它工作得很好,一旦我将它上传到我的服务器上,我注意到我遇到了一些错误,来找出答案,jason_decode从PHP 5.2开始成为标准,我的服务器是运行 PHP 4 并且不起作用。
有没有一种简单的方法,无需编译新版本的 PHP 或添加库即可使其与 PHP 4 一起使用?
感谢您的帮助!
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!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
看看这篇文章,也许这可以帮助你
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
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
是的。
查看 json 网站。
您可以使用 PECL json 包
或 Blueberryware
或者如果您使用的是 codeigniter
Yep.
Check out the json website.
You could use the PECL json package
Or Blueberryware
Or if you are using codeigniter
当您的脚本与 PHP5 一起使用时,您会发现 PHP4 的最好的两个 json_decode() 和 json_encode() 实现具有优雅的降级:
http://www.abeautifulsite.net/blog/2008/05/using-json-encode-and-json-decode-in-php4/
(另请阅读评论)
和这个(同样有一些曲折):
http://www.epigroove.com/posts/97/how_to_use_json_in_php_4_or_php_51x
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