URL中的cURL和特殊字符

I am using curl_setopt($ch, CURLOPT_URL, $link) for fetching an external site, but there are special characters (&, ?, ;) in some urls and curl not work.

i used urldecode but still no luck, also replaced special characters with encoded ones (for example, %26 instead of &), but source site only returns a 404 page.

http://www.php.net/manual/en/function.curl-escape.php

// Create a curl handle $ch = curl_init();

// Escape a string used as a GET parameter $location = curl_escape($ch, 'Hofbräuhaus / München'); // Result: Hofbr%C3%A4uhaus%20%2F%20M%C3%BCnchen

// Compose an URL with the escaped string $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 the handle curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_exec($ch); curl_close($ch);

curl_escape function is only available since PHP 5.5.

An other solution is to use the function encode_url written here : http://publicmind.in/blog/url-encoding/ It work perfectly for me!