Answer the question
In order to leave comments, you need to log in
How to fix the encoding in when parsing?
I'm trying to ask the page, but at the output I get the wrong encoding in cracks.
My site is on windows-1251
How to solve the problem?
$file = file_get_contents('https://tv.yandex.ru/213/channels/150?date=2016-04-12&period=all-day');
$dom = new DOMDocument('1.0', 'utf-8');
$dom->loadHTML($file);
$xpath = new DOMXPath($dom);
$schedule_items = $xpath->query('//div[@class="b-tv-channel-schedule__item"]');
$count = $schedule_items->length;
if ($count > 0) {
for ($i = 0; $i < $count; $i++) {
$item = $schedule_items->item($i);
$event_time = $xpath->query('a/span[@class="tv-event__time"]/span[@class="tv-event__time-text"]', $item);
$event_title = $xpath->query('a/div[@class="tv-event__title"]/div[@class="tv-event__title-inner"]', $item);
if ($event_time->length > 0 && $event_title->length > 0) {
$result .= $event_time->item(0)->nodeValue.$event_title->item(0)->nodeValue;
}
}
$teleprogramma .= "<h3><a href='#'>".$day_title."</a></h3><div>".$result."</div>";
}
Answer the question
In order to leave comments, you need to log in
My site is on windows-1251
$dom = new DOMDocument('1.0', 'utf-8');
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question