English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Basic PHP Tutorial

Advanced PHP Tutorial

PHP & MySQL

PHP Reference Manual

PHP curl_escape() Function Usage and Example

PHP CURL Reference Manual

(PHP 5 >= 5.5.0)

curl_escape — URL encodes the given string.

Syntax

string curl_escape ( resource $ch , string $str )

This function performs URL encoding on the given string.

Parameter

ch

The CURL handle returned by curl_init().

str

Encoded string

Return value

Returns the encoded string, or FALSE on failure.

Online Example

<?php
// Create a CURL handle
$ch = curl_init();
// Encode GET parameters
$location = curl_escape($ch, 'Hofbräuhaus / München');
// Result: Hofbr%C3%A4uhaus%20%2F%20M%C3%BCnchen
// Compare the encoded 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
// Send HTTP request and close handle
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_exec($ch);
curl_close($ch);
?>

PHP CURL Reference Manual