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リファレンスマニュアル