Answer the question
In order to leave comments, you need to log in
The parser outputs information in the wrong encoding
Help 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 />";
}
?>
Answer the question
In order to leave comments, you need to log in
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.
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 questionAsk a Question
731 491 924 answers to any question