PHP curl_escape函數(shù)
(PHP 5 >= 5.5.0)
curl_escape — 對給定的字符串進行URL編碼。
說明
string curl_escape ( resource $ch , string $str )
該函數(shù)對給定的字符串進行URL編碼? RFC 3986。
參數(shù)
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); ?>
更多建議: