A
A
Alexey2014-04-19 11:59:38
PHP
Alexey, 2014-04-19 11:59:38

The parser outputs information in the wrong encoding

a9b362a11f5845f3b39a88eb31a6c188.jpgHelp me solve the problem, there is a Wordpress site with a module that allows you to display php on the page, everything works, but I have implemented a holiday parser, and it displays information from the calend.ru site in the wrong encoding, my site is in UTF-8, they are in windows-1251 , here is the parser code:

<?php
 $rss = simplexml_load_file("http://www.calend.ru/img/export/calend.rss");

echo "<b>Ближайшие праздники:</b><br />";
 
foreach ($rss->channel->item as $item) {

    echo iconv("Windows-1251", "UTF-8", $item->title)."<br />";
} 
    ?>

I am attaching a screenshot of what it looks like.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
B
begemot_nn, 2014-04-19
@begemot_nn

for future generations, it will be useful if you write - how it was solved. In this case, a person with a similar problem will be able to find a solution by searching.

A
Alexey, 2014-04-19
@rofn

Issue resolved

R
Romua1d, 2015-11-05
@Romua1d

Solution of the problem:

<?php
setlocale(LC_ALL, 'ru_RU.UTF-8');
header('Content-type: text/html; charset=utf-8');
 $rss = simplexml_load_file("http://www.calend.ru/img/export/calend.rss");

echo "<b>Ближайшие праздники:</b><br />";
 
foreach ($rss->channel->item as $item) {

    echo  $item->title."<br />";
} 
    ?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question