D
D
dura2282019-09-16 22:14:13
PHP
dura228, 2019-09-16 22:14:13

Why does phpQuery get the page in windows-1251 encoding, although before that I converted the string to utf-8?

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once __DIR__ . '/vendor/autoload.php';

$f = file_get_contents('http://gramota.ru/slovari/info/petr/imsm/');

$str = iconv( "windows-1251", "utf-8", $f);
$document = \phpQuery::newDocumentHTML($str);
var_dump($document);

The $document variable has its "textContent" property set to a shorthand string, but $str outputs normal text.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nujabes37, 2019-09-16
@dura228

$document = phpQuery::newDocumentHTML($str, $charset="utf-8");

Or
$document = phpQuery::newDocumentHTML('<meta http-equiv="content-type" content="text/html; charset=utf-8" />'.$str);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question