Question mark in PHP CURL answer

I want to use one site with API, I have this code:

$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);

      

but I see ?

instead of some characters, such as "

, ยป

. I checked the original page and the charset is utf-8 .. what is the problem?

+3


source to share


1 answer


I think you missed the CURLOPT_ENCODING option

Please try the following code.



$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);

      

+6


source







All Articles