PHP URL中的CURL与变音符号

时间:2012-07-03 20:01:22

标签: php url curl

我有卷曲问题: 我从Mysql(城市名称)获取数据,其中的变音符号用ascii HEX编码(例如,%DF为ß或%DC为ü)。 我用str_replace()转换它们;到德国的变形金刚(ß,ü,ä,ö)。 当我用curl发送数据(城市)时,我收到错误。(“填写正确!”

当我发送没有变音符号(ä,ö,ü,ß)的数据时,一切都很好! 我的代码或卷曲有什么问题。我也尝试过w / shell - 同样的问题!

$this->url = "blah.org/?params=diesdas&city_from=Straßbourg&City_to=München";

$this->ckfile = tempnam("/tmp", "cookie");
$this->ch = curl_init();
curl_setopt($this->ch,CURLOPT_URL, $this->url);
curl_setopt($this->ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($this->ch, CURLOPT_PROXY, "46.4.248.80");
curl_setopt($this->ch, CURLOPT_PROXYPORT, "3128");
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->ch, CURLOPT_COOKIEJAR, $this->ckfile);
echo 'getting cookie file...';
$cookie = curl_exec($this->ch);
if($cookie = false){echo 'couldn\'t get cookie!<br> '.curl_error($this->ch);}else{echo 'got cookie! omnomnom!<br>';}

$this->ch = curl_init("blah.com/sendcookietome");
curl_setopt($this->ch, CURLOPT_COOKIEFILE, $this->ckfile);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($this->ch, CURLOPT_PROXY, "46.4.248.80");
curl_setopt($this->ch, CURLOPT_PROXYPORT, "3128");
curl_exec($this->ch);

最好,meeeeeh!

3 个答案:

答案 0 :(得分:0)

如果您在GET或POST数据中使用它们,则需要对这些字符进行url编码。不要解码它们。

答案 1 :(得分:0)

对你的城市使用rawurlencode()。

http://php.net/manual/en/function.rawurlencode.php

你也错过了Straßburg .... ...

在你的例子中:

$cityname =rawurlencode('Straßburg');

$url ='http://bahn.ltur.com/index/search/?mnd=de&lang=de_DE&searchin=DE-SB-VI&trip_mode=trip_simple&from_spar='.$cityname.'&to_spar=Haiger&start_datum=04.07.2012&start_time=06%3A30&end_datum=06.07.2012&end_time=16%3A42&SEA_adults=1&SEA_kids1=0&SEA_kids2=0&SEA_adult1=&SEA_adult2=&SEA_adult3=&SEA_adult4=&SEA_adult5=&SEA_kid11=&SEA_kid12=&SEA_kid13=&SEA_kid14=&SEA_kid15=&trainclass_spar=2&x=54&y=15
';

//do your curl thing..

答案 2 :(得分:0)

我得到了它的工作: wow.wtf?

此链接适用于'ß':     blah.org/&from_spar=Straßburg&to_spar=Kiel+Hbf     blah.org/&from_spar=Köln+Hbf&to_spar=Stuttgart+Hbf

这是怎么被接受的。