【问题标题】:How to post a Bitlink shortened URL to input value如何将 Bitlink 缩短的 URL 发布到输入值
【发布时间】:2015-12-05 19:52:05
【问题描述】:

以下是我用于通过 Bitly API 缩短长 URL 的 PHP 代码:

<?php
$bitly_access_token = 'my_api_key';
$deeplink = 'http://example.com/';

$curl = curl_init('https://api-ssl.bit.ly/v3/shorten?access_token='.$bitly_access_token.'&longUrl='.urlencode($deeplink));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($curl, CURLOPT_HEADER, 0);
$return = json_decode(curl_exec($curl), true);
curl_close($curl);

print_r($return);
?>

上述代码的示例输出:

数组 ( [status_code] => 200 [status_txt] => OK [数据] => 数组 ( [long_url] => http://example.com [url] => http://bit.ly/xxxxx [哈希] => xxxxx [global_hash] => zzzzz [new_hash] => 0 ) )

它可以工作并将缩短的 url 输出为:http://bit.ly/xxxxx (Sample)。

但是,凭借一点 PHP 经验,我无法弄清楚如何将缩短的 URL 发布到输入值中。我试过&lt;input type="text" value="&lt;?php echo $return ?&gt;" /&gt;,但没用。

另外,我对这个长输出有疑问,为什么它不只显示缩短的 URL?

谢谢。

【问题讨论】:

标签: php curl bit.ly


【解决方案1】:

也许是这样的:

<input type="text" value="<?php echo $return['data']['url'] ?>" />

【讨论】:

    猜你喜欢
    • 2019-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-24
    • 1970-01-01
    • 1970-01-01
    • 2016-04-08
    相关资源
    最近更新 更多