我正在使用CURL来获取Yahoo!带有unicode查询的BOSS api url,但是我收到了“错误请求”错误。
http://boss.yahooapis.com/ysearch/web/v1/கமல்ஹாசன்?appid={appid}&format=xml
上面的url工作正常,并在firefox中返回结果。
请有人帮我解决这个问题。
$url = "http://boss.yahooapis.com/ysearch/web/v1/கமல்ஹாசன்?appid={appid}&format=xml";
$ch - curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = curl_exec($ch);
curl_close($ch);
答案 0 :(得分:0)
您必须对您的网址进行 urlencode。 遵循以下代码:
$url = "http://yoursite.com/some-unicode-chars"
$path = parse_url($url, PHP_URL_PATH);
if ($path) {
$segments = explode('/', $path);
foreach($segments as $index => $segment) {
$segments[$index] = urlencode($segment);
}
$url = str_replace($path, implode('/', $segments), $url);
}
// then use url in your curl command:
$handle = curl_init($url);
// ...
答案 1 :(得分:-7)
拿出那个கமல்ஹாசன்字并使用 PHP中的Mysql_realescape字符串。
此致 ARCHIT。