博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
reddit_使用PHP和JSON获取URL的Reddit分数
阅读量:2524 次
发布时间:2019-05-11

本文共 1194 字,大约阅读时间需要 3 分钟。

reddit

Reddit Guy

Since we can see Digg turning more into a funny-pic-and-vid site each day, I've turned my attention to Reddit. Reddit just seems more controlled and programmer-friendly. Since I have respect for Reddit I thought I'd put together a quick tutorial on how you can retrieve a URL's Reddit score using PHP.

由于我们每天都能看到Digg变成一个有趣的生动视频网站,因此我将注意力转向Reddit。 Reddit似乎更具控制​​性且对程序员更友好。 由于我尊重Reddit,所以我想整理一个快速教程,介绍如何使用PHP检索URL的Reddit分数。

PHP (The PHP)

"; //21 echo "Downs: $downs
"; //8 echo "Score: $score
"; //13 /* utility function: go get it! */ function get_url($url) { $ch = curl_init(); curl_setopt($ch,CURLOPT_URL,$url); curl_setopt($ch,CURLOPT_RETURNTRANSFER,1); curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1); $content = curl_exec($ch); curl_close($ch); return $content; }?>

Parsing the JSON is simple using json_encode with the value of true to make turn the JSON into an associate array. My example shows how you can grab the number of "ups" and "downs" -- not just the score. As with every API/web service, I highly recommend caching the result of your request.

使用json_encode和true值来解析JSON很简单,可以将JSON转换为关联数组。 我的示例显示了如何获取“上升”和“下降”的数量-而不仅仅是分数。 与每个API / Web服务一样,我强烈建议您缓存请求的结果。

翻译自:

reddit

转载地址:http://ecpwd.baihongyu.com/

你可能感兴趣的文章
好程序员web前端教程:对象
查看>>
十道海量数据处理面试题与十个方法大总结
查看>>
sql表操作的基础语法
查看>>
【hdoj_1049】Climbing Worm
查看>>
android 开发之 - 百度地图 key 的申请
查看>>
SQL切换真假状态标识字段
查看>>
MySQL的数据类型
查看>>
获取控件在运行时于屏幕中的位置
查看>>
删除多个重复记录
查看>>
Meteor Shower POJ - 3669
查看>>
urllib
查看>>
.Net内存程序集的DUMP(ProFile篇)
查看>>
《Linux命令行与shell脚本编程大全 第3版》高级Shell脚本编程---40
查看>>
NIOS II 中用结构体指示灯终于正常了
查看>>
CF1009F Dominant Indices - 题解
查看>>
memached实现tomcat的session共享
查看>>
django导出excel
查看>>
阿里云服务器CentOS6.9安装maven
查看>>
【搜索】数的划分
查看>>
智能提示
查看>>