CakeFest 2024: The Official CakePHP Conference

curl_unescape

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

curl_unescape解码指定 URL 编码的字符串

说明

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

该函数解码指定 URL 编码的字符串。

参数

handle

curl_init() 返回的 cURL 句柄。

string

需要解码的 URL 编码字符串。

返回值

返回解码后的字符串 或者在失败时返回 false

更新日志

版本 说明
8.0.0 handle 现在接受 CurlHandle 实例;之前接受 resource

示例

示例 #1 curl_escape() 示例

<?php
// 创建 curl 句柄
$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"

// 关闭句柄
curl_close($ch);
?>

注释

注意:

curl_unescape() 不会将加号 (+) 解码成空格。而 urldecode() 会。

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top