(PHP 5 >= 5.5.0)
curl_escape — 對給定的字符串進(jìn)行URL編碼。
string curl_escape ( resource $ch , string $str )
該函數(shù)對給定的字符串進(jìn)行URL編碼。
ch
由 curl_init() 返回的 CURL 句柄。
str
編碼字符串
返回編碼字符串,或者在失敗時返回 FALSE。
<?php
// 創(chuàng)建一個CURL句柄
$ch = curl_init();
// 編碼GET參數(shù)
$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
// 發(fā)送HTTP請求并關(guān)閉句柄
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
?>