在&符号后将字符串传递给twitter失败

kit*_*ski 2 php twitter parsing

早上好,

我正在尝试使用以下代码将字符串传递给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);
Run Code Online (Sandbox Code Playgroud)

然而,在twitter上出现的所有内容都是链接

http://www.smartphonesoft.com/index.php?option=com_mtree

在这里可以看到http://twitter.com/smartphonesft

如何在&符之后传递所有内容?

Sar*_*raz 7

您需要使用以下代码对网址进行编码urlencode:

$message = urlencode($message);
Run Code Online (Sandbox Code Playgroud)