早上好,
我正在尝试使用以下代码将字符串传递给twitter
// The message you want to send
$message = "http://www.smartphonesoft.com/index.php?option=com_mtree&task=viewlink&link_id=" .$link_id . " " ."Android Software" . " " .$link_name . " " . $metadesc;
// The twitter API address
$url = 'http://twitter.com/statuses/update.xml';
// Alternative JSON version
// $url = 'http://twitter.com/statuses/update.json';
// Set up and execute the curl process
$curl_handle = curl_init();
curl_setopt($curl_handle, CURLOPT_URL, "$url");
curl_setopt($curl_handle, CURLOPT_CONNECTTIMEOUT, 2);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl_handle, CURLOPT_POST, 1);
curl_setopt($curl_handle, CURLOPT_POSTFIELDS, "status=$message");
curl_setopt($curl_handle, CURLOPT_USERPWD, "$username:$password");
$buffer = curl_exec($curl_handle);
curl_close($curl_handle);
然而,推特上出现的所有内容都是指向
的链接http://www.smartphonesoft.com/index.php?option=com_mtree
在这里可以看到http://twitter.com/smartphonesft
如何在&符之后传递所有内容?
答案 0 :(得分:7)
您需要使用urlencode
编码网址:
$message = urlencode($message);
答案 1 :(得分:0)
另请注意,如果您使用的是JavaScript,则需要致电encodeURIComponent()
而不是encodeURI()
encodeURIComponent():
, / ? : @ & = + $ #