How to set the encoding curl?

Trying to get DOM tree using curl, but it is impossible to set the encoding.

Here is the code:
function curl_get($url, $referer = 'www.google.com') {
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_HEADER, 0);
 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36");
 curl_setopt($ch, CURLOPT_REFERER, $referer);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 $data = curl_exec($ch);
curl_close($ch);
 return $data;
}

$html = curl_get('https://www.potehechas.ru/club/fact_1.shtml');

// file_put_contents('1.txt', $html);
echo $html;


That .htaccess:
#AddDefaultCharset UTF-8
AddDefaultCharset WINDOWS-1251


Here's what happens:
5e96aa0417998088369655.png
April 19th 20 at 12:04
2 answers
April 19th 20 at 12:06
Solution
Resolved the issue with iconv.
iconv UNIX utility to convert text from one encoding to another. Also ported to Windows.

Here is the code:
function curl_get($url, $referer = 'www.google.com') {
 $ch = curl_init();
 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_HEADER, 0);
 curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36");
 curl_setopt($ch, CURLOPT_REFERER, $referer);
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
 $data = curl_exec($ch);
curl_close($ch);
 $body = iconv('windows-1251', 'UTF-8', $data);
 return $body;
}
$html = curl_get('https://www.potehechas.ru/club/fact_1.shtml');
echo $html;
Why did you commented out the normal encoding in htaccess? - Leonie commented on April 19th 20 at 12:09
@Leonie, Because it failed to take in normal encoding. Everything comes from ? - Rasheed commented on April 19th 20 at 12:12
what does "accept" if the htaccess to Kurla irrelevant? - Leonie commented on April 19th 20 at 12:15
@Leonie, XS. I do not rummage. Only the day before began to teach - Rasheed commented on April 19th 20 at 12:18
April 19th 20 at 12:08
Well add the code
curl_setopt(CURLOPT_HTTPHEADER, array("Accept-Charset: WINDOWS-1251"));
if it helps...

Find more questions by tags PHP