2010-06-21 5 views
2

Bonjour,Passing chaîne à twitter échoue après esperluette

Je suis en train de passer d'une chaîne à Twitter, en utilisant le code suivant

// 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); 

Cependant tout ce qui apparaît sur twitter est un lien vers

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

comme on peut le voir ici http://twitter.com/smartphonesft

Comment puis-je faire passer tout après l'esperluette?

Répondre

7

Vous devez encoder l'URL avec urlencode:

$message = urlencode($message); 
0

Notez également que si vous utilisez JavaScript, vous devez appeler encodeURIComponent() et non encodeURI()

encodeURIComponent() est nécessaire pour ce qui suit caractères spéciaux:

,/? : @ & = + $ # 
Questions connexes