PHP curl_escape函數
(PHP 5 >= 5.5.0)
curl_escape — 對給定的字串進行URL編碼。
說明
string curl_escape ( resource $ch , string $str )
該函數對給定的字串進行URL編碼» RFC 3986。
參數
ch
由 curl_init() 返回的 cURL 句柄。
str
編碼字串
返回值
返回編碼字串,或者在失敗時返回 FALSE。
實例
<?php
// 創建一個cURL句柄
$ch = curl_init();
// 編碼GET參數
$location = curl_escape($ch, 'Hofbräuhaus / München');
// Result: Hofbr%C3%A4uhaus%20%2F%20M%C3%BCnchen
// 比較編碼後的URL
$url = "http://example.com/add_location.php?location={$location}";
// Result: http://example.com/add_location.php?location=Hofbr%C3%A4uhaus%20%2F%20M%C3%BCnchen
// 發送HTTP請求並關閉句柄
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
?>

PHP cURL參考手冊