Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/274.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 回答中的问号_Php_Curl_Encoding_Character Encoding - Fatal编程技术网

Php 回答中的问号

Php 回答中的问号,php,curl,encoding,character-encoding,Php,Curl,Encoding,Character Encoding,我想使用一个带有API的站点, 我有以下代码: $ch=curl_init('http://example.com/?api=**'); $options = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array('text/plain;charset=UTF-8') , ); curl_setopt_array( $ch, $options ); $results=curl_exec(

我想使用一个带有API的站点, 我有以下代码:

$ch=curl_init('http://example.com/?api=**');
$options = array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => array('text/plain;charset=UTF-8') ,
);

curl_setopt_array( $ch, $options );
$results=curl_exec($ch);
var_dump($results);
但是我看到的是
,而不是像
这样的字符。 我检查了源页面,字符集是utf-8。。
有什么问题吗?

我想你错过了选择CURLOPT\u编码

请尝试以下代码

$ch = curl_init('http://example.com/?api=**');
curl_setopt($ch, CURLOPT_HTTPHEADER, 'text/plain;charset=UTF-8');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_ENCODING, 'UTF-8');
$results = curl_exec($ch);
var_dump($results);

仅仅因为源页面是utf 8,并不意味着输出的是utf-8。如果您的Web服务器正在向您查看结果的浏览器发送iso-8859-1,该怎么办?如何知道Web服务器编码是否为utf-8?请检查您的浏览器。e、 火狐的“工具->页面信息”。它会告诉我要使用什么编码。这是utf-8,但页面信息会告诉我Web服务器响应编码还是页面编码?您好@user1903750,请告诉我这是否有帮助。感谢OMG,这解决了我的
问题。