【问题标题】:Return a List of links in reddit using PHP使用 PHP 返回 reddit 中的链接列表
【发布时间】:2012-07-22 04:30:31
【问题描述】:

只是想知道是否有人有示例代码来返回 reddit 的前 25 个链接(使用 PHP)。在 JSON 或 XML 中。我无法理解 API……而且很少使用 python。

【问题讨论】:

  • 您能发布到目前为止您尝试过的内容吗?

标签: php reddit


【解决方案1】:
$array = (array) json_decode(file_get_contents("http://www.reddit.com/.json"));

这将返回一个 PHP 数组,其中包含来自首页的所有数据。您可以使用简单的 while() 循环来限制显示的数量。

现在你已经有了上面的数组,这很简单,因为你所要做的就是单步调试它。

【讨论】:

  • 这行得通,谢谢。只是在 php 中挖掘如此深的数组时遇到了麻烦。例如第一个标题在这里。 Array ( [0] => stdClass Object ( [kind] => t3 [data] => stdClass Object ( [domain] => imgur.com [banned_by] => [media_embed] => stdClass Object ( ) [subreddit] = > 有趣的 [selftext_html] => [selftext] => [likes] => [link_flair_text] => [id] => x2gx8 [clicked] => [title] => 你在做什么?有什么快速的技巧吗?谢谢
猜你喜欢
  • 2020-12-25
  • 1970-01-01
  • 2018-05-10
  • 2019-08-14
  • 1970-01-01
  • 1970-01-01
  • 2023-01-24
  • 2020-10-22
  • 1970-01-01
相关资源
最近更新 更多