PHP Conference Japan 2024

curl_unescape

(PHP 5 >= 5.5.0, PHP 7, PHP 8)

curl_unescape解碼指定的 URL 編碼字串

說明

curl_unescape(CurlHandle $handle, 字串 $string): 字串|false

此函式會解碼指定的 URL 編碼字串。

參數

handle

curl_init() 返回的 cURL 句柄。

string

要解碼的 URL 編碼字串。

返回值

返回已解碼的字串,或在失敗時返回 false

更新日誌

版本 說明
8.0.0 handle 現在預期是一個 CurlHandle 實例;先前預期的是一個 資源

範例

範例 #1 curl_escape() 範例

<?php
// 建立一個 curl handle
$ch = curl_init('http://example.com/redirect.php');

// 送出 HTTP 請求並跟隨重新導向
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_exec($ch);

// 取得最後實際的 URL
$effective_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
// 例如: "http://example.com/show_location.php?loc=M%C3%BCnchen"

// 解碼 URL
$effective_url_decoded = curl_unescape($ch, $effective_url);
// "http://example.com/show_location.php?loc=München"

// 關閉 handle
curl_close($ch);
?>

注意事項

注意:

curl_unescape() 不會將加號 (+) 解碼為空格。 urldecode() 則會。

參見

新增筆記

使用者貢獻的筆記

此頁面沒有使用者貢獻的筆記。
To Top