在Curl请求中更改的字符 [英] characters changed in a Curl request

查看:126
本文介绍了在Curl请求中更改的字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我看到XML数据源,我得到与下面的代码,特殊字符在XML代码是正确的。
但是当Curl返回数据时,字符ó和ä ó和ä。
此转换发生在所有特殊字符,这2个只是一个例子。

When I look at the XML data feed i get with the below code, special characters are correct in the XML code. However when Curl returns the data, characters like "ó" and "ä" are converted into resp. "ó" and "ä". This conversion happens to all special characters, these 2 are just an example.

$myvar = curl_init();
$myURL = "http://someurl.com/";
curl_setopt($myvar, CURLOPT_USERAGENT, '[Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2")]');
curl_setopt($myvar, CURLOPT_URL, $myURL);
curl_setopt($myvar, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($myvar, CURLOPT_TRANSFERTEXT, TRUE);
curl_setopt($myvar, CURLOPT_CONNECTTIMEOUT,3);
$xmlstr = curl_exec ($myvar);

的XML文件说编码如下?xml version =1.0encoding =UTF-8?

The header of the XML file says to encode as follows "?xml version="1.0" encoding="UTF-8"?"

我想要的是获得相同的字符

All I want is to get the same characters to show up in the Curl result without any transformation.

希望我只是错过了一些简单的步骤,期待任何答案。

Hoping i just missed some plain easy step, looking forward to any answers.

最好的问候
Fons

Best regards Fons

推荐答案

如何知道 $ xmlstr 包含错误的字节?如果你在某种终端窗口的输出,可能的问题是,终端不支持UTF-8,而不是cURL被打破。

How do you know $xmlstr contains the wrong bytes? If you're looking at the output in a terminal window of some sort, it's probable that the problem is that the terminal does not support UTF-8, not that cURL is broken.

cURL不关心UTF-8或任何其他字符编码 - 它的工作只是从某处获取一系列字节。它不可能做任何东西,将特别角色。如果你使用cURL的方式有什么问题,它会破坏一切,而不只是非ASCII字符。

cURL doesn't care about UTF-8 or any other character encoding - its job is just to fetch a sequence of bytes from somewhere. It's not likely to be doing anything that will mangle special characters. If there's something wrong with the way you're using cURL, it'll be mangling everything, not just non-ASCII characters.

这篇关于在Curl请求中更改的字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆