PHP CURL响应中的问号

use*_*750 3 php encoding curl 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($ch);
var_dump($results);
Run Code Online (Sandbox Code Playgroud)

但我看到?的,而不是像一些字符,».我检查了源页面和charset是utf-8 ..有什么问题?

OMG*_*OMG 7

我猜你错过了选项CURLOPT_ENCODING

请尝试以下代码.

$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);
Run Code Online (Sandbox Code Playgroud)