bit.ly php api - 在 '&' 之后删除查询字符串参数象征?
我有一个 Flash 应用程序,其中包含自定义迷你应用程序的 Twitter 共享。
我非常简单地使用通过 php 查询字符串传入的 flashvars 来实现此目的,以便将您的自定义颜色和消息传递到迷你应用程序。
当然,问题是 twitter 的 url 长度,所以我希望使用 PHP 的 bit.ly api 来缩短动态 url 并将该散列 url 传递回 flash。
我已经编写了一个函数来执行此操作,该函数运行良好,但是它会在第一个“&”之后删除第二个查询字符串参数象征?
例如,运行 url 'http://s46264.gridserver.com/apps/soundgirl/fbwall.php?colour=red&message=twittertest' 的以下函数
会缩短为 http://bit.ly/i4kfj0 解析后会变成 http://s46264.gridserver.com/apps/soundgirl/fbwall.php?colour=red
它正在砍掉第二个查询字符串参数。有人知道我可以阻止这种情况发生吗?
谢谢。
<?php
function bitly_shorten($url)
{
$username = "modernenglish";
$apikey = "myapikey";
$response = file_get_contents("http://api.bit.ly/v3/shorten?login=$username&apiKey=$apikey&longUrl=$url&format=json");
$response = json_decode($response);
if ($response->status_code == 200 && $response->status_txt == "OK")
{
return $response->data->url;
} else
{
return null;
}
}
$link = urldecode("http://s46264.gridserver.com/apps/soundgirl/fbwall.php?colour=red&message=twittertest");
echo bitly_shorten($link);
?>
I've got a Flash app that includes a twitter share for a customized mini application.
I'm achieving this very simply using flashvars passed in via a php querystring so your custom colour and message are passed to the mini-app.
The problem of course is url length for twitter so i'm looking to use the bit.ly api for php to shorten the dynamic url and pass that hashed url back to flash.
I've written a function to do this which works fine however it is chopping off the second querystring parameter after the first '&' symbol?
So for example, the following function running the url 'http://s46264.gridserver.com/apps/soundgirl/fbwall.php?colour=red&message=twittertest'
Gets shortened to http://bit.ly/i4kfj0 which, when parsed becomes http://s46264.gridserver.com/apps/soundgirl/fbwall.php?colour=red
It's chopping off the second querystring parameter. Anyone know of a way I can stop this from happening?
Thanks.
<?php
function bitly_shorten($url)
{
$username = "modernenglish";
$apikey = "myapikey";
$response = file_get_contents("http://api.bit.ly/v3/shorten?login=$username&apiKey=$apikey&longUrl=$url&format=json");
$response = json_decode($response);
if ($response->status_code == 200 && $response->status_txt == "OK")
{
return $response->data->url;
} else
{
return null;
}
}
$link = urldecode("http://s46264.gridserver.com/apps/soundgirl/fbwall.php?colour=red&message=twittertest");
echo bitly_shorten($link);
?>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许可以尝试:
在调用
bitly_shorten()
之前不使用urldecode()
:将 URL 上的
urlencode()
添加到bitly_shorten()< /代码> 功能:
Maybe try:
No
urldecode()
before callingbitly_shorten()
:Add
urlencode()
on the URL into yourbitly_shorten()
function: