Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Question mark in PHP CURL response

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 like , » . i checked source page and charset is utf-8.. what is problem?

like image 477
user1903750 Avatar asked Oct 28 '25 08:10

user1903750


1 Answers

I guess you missed the option CURLOPT_ENCODING

Please try 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);
like image 93
Jirilmon Avatar answered Oct 30 '25 23:10

Jirilmon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!