【问题标题】:bit.ly dynamic link phpbit.ly 动态链接 php
【发布时间】:2012-10-13 02:36:48
【问题描述】:

我正在尝试在我的网站中使用 bit.ly。当我这样做时:

$short_url = json_decode(file_get_contents("http://api.bit.ly/v3/shorten?login=myLogin&apiKey=myApiKey&longUrl=".urlencode("http://example.com")."&format=json"))->data->url;

效果很好。

但是,当我尝试将链接放在变量中时。

$link = 'http://example.com';
$short_url = json_decode(file_get_contents("http://api.bit.ly/v3/shorten?login=myLogin&apiKey=myApiKey&longUrl=".urlencode(**$link**)."&format=json"))->data->url;

它不起作用。任何帮助将不胜感激。

【问题讨论】:

  • "It doesn't work" - 非常模棱两可。怎么了?应该怎么办?
  • 无输出。如果我回显 $short_url 它是空白的
  • 好的,看看你的问题。我已经格式化了,你能验证它和你写的完全一样吗?
  • 首先,确保传递给file_get_contents() 的字符串匹配。然后,查看(并编辑)file_get_contents() 的输出,然后将其传递给json_decode()
  • 我真的不明白你在说什么

标签: php variables dynamic hyperlink bit.ly


【解决方案1】:

检查file_get_contents() 的输出是什么。你可以这样做:

var_dump(file_get_contents("http://api.bit.ly/v3/shorten?login=myLogin&apiKey=myApiKey&longUrl=".urlencode($link)."&format=json"));

如果那里有良好的输出,请检查并将其传递给json_encode()

【讨论】:

  • 是的,我知道它只是为了强调这个词。这是在这个网站上加粗。你所拥有的就是我在我的网站上拥有的。
  • @user939951 我已经更新了答案。试试看,然后告诉我。
  • 好的,立即将我的答案中的内容输出并在问题中更新。
  • 我真的不知道如何诚实
  • 感谢您的帮助,我将使用您的答案作为正确答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-08
  • 2019-04-20
  • 2014-09-01
  • 1970-01-01
  • 2014-06-28
  • 1970-01-01
相关资源
最近更新 更多