вопрос
Здравствуйте, имеется парсер он же модуль "гороскоп". Сайт в кодировке win-1251, а парсер стал с недавних пор получать информацию в utf-8 и часть сайта в иероглифах. Я так полагаю в модуле нужно использовать функцию iconv но мои знания в PHP мешают этому.
Вот сам модуль:
Вот сам модуль:
<?
if(!defined('DATALIFEENGINE'))
{
die("Hacking attempt!");
}
############## Читаем кэш ################
function horos_cache($prefix, $cache_id=false){
global $config;
if ($config['allow_cache'] != "yes") return false;
if (!$cache_id) {
$filename = ENGINE_DIR.'/cache/'.$prefix.'.tmp';
} else {
$cache_id = totranslit ($cache_id);
$filename = ENGINE_DIR."/cache/".$prefix."_".$cache_id.".tmp";
}
return @file_get_contents($filename);
}
############## Кэшируем ################
function addto_cache($prefix, $cache_text, $cache_id=false){
global $config;
if ($config['allow_cache'] != "yes") return false;
if (!$cache_id) {
$filename = ENGINE_DIR.'/cache/'.$prefix.'.tmp';
} else {
$cache_id = totranslit ($cache_id);
$filename = ENGINE_DIR."/cache/".$prefix."_".$cache_id.".tmp";
}
$fp = fopen($filename, 'wb+');
fwrite($fp, $cache_text);
fclose($fp);
@chmod($filename, 0666);
}
$tpl->load_template('horoscope.tpl');
$title = "Овен";
$pic = "<img src=\"{THEME}/images/zodiac/aries.gif\" marginwidth=\"5\">";
$sign="aries";
$time = $_GET['time'];
$timerus = array(
'' => "Гороскоп на сьогодні",
'yesterday' => "Вчорашній гороскоп",
'tomorrow' => "Гороскоп на завтра",
'week' => "Гороскоп на тиждень",
'month' => "Гороскоп на місяць",
'year' => "Гороскоп на рік",
);
switch ($_GET['sign']) {
case "aries" :
$act=1;
$pic = "<img src=\"{THEME}/images/zodiac/aries.gif\" marginwidth=\"5\">";
$title = "Овен";
$metatags['title'] = "".$title." > ".$timerus[$time] ." > ".$config['home_title']."";
break;
case "taurus":
$act=2;
$pic = "<img src=\"{THEME}/images/zodiac/taurus.gif\" marginwidth=\"5\">";
$title = "Тілець";
$metatags['title'] = "".$title." > ".$timerus[$time] ." > ".$config['home_title']."";
break;
case "gemini" :
$act = 3; $pic = "<img src=\"{THEME}/images/zodiac/gemini.gif\" marginwidth=\"5\">";
$title = "Близнюки";
$metatags['title'] = "".$title." > ".$timerus[$time] ." > ".$config['home_title']."";
break;
case "cancer" :
$act = 4; $pic = "<img src=\"{THEME}/images/zodiac/cancer.gif\" marginwidth=\"5\">";
$title = "Рак";
$metatags['title'] = "".$title." > ".$timerus[$time] ." > ".$config['home_title']."";
break;
case "leo" :
$act = 5; $pic = "<img src=\"{THEME}/images/zodiac/leo.gif\" marginwidth=\"5\">";
$title = "Лев";
$metatags['title'] = "".$title." > ".$timerus[$time] ." > ".$config['home_title']."";
break;
case "virgo" :
$act = 6; $pic = "<img src=\"{THEME}/images/zodiac/virgo.gif\" marginwidth=\"5\">";
$title = "Діва";
$metatags['title'] = "".$title." > ".$timerus[$time] ." > ".$config['home_title']."";
break;
case "libra" :
$act = 7; $pic = "<img src=\"{THEME}/images/zodiac/libra.gif\" marginwidth=\"5\">";
$title = "Терези";
$metatags['title'] = "".$title." > ".$timerus[$time] ." > ".$config['home_title']."";
break;
case "scorpio" :
$act = 8; $pic = "<img src=\"{THEME}/images/zodiac/scorpio.gif\" marginwidth=\"5\">";
$title = "Скорпіон";
$metatags['title'] = "".$title." > ".$timerus[$time] ." > ".$config['home_title']."";
break;
case "sagittarius" :
$act = 9; $pic = "<img src=\"{THEME}/images/zodiac/sagittarius.gif\" marginwidth=\"5\">";
$title = "Стрілець";
$metatags['title'] = "".$title." > ".$timerus[$time] ." > ".$config['home_title']."";
break;
case "capricorn" :
$act = 10; $pic = "<img src=\"{THEME}/images/zodiac/capricorn.gif\" marginwidth=\"5\">";
$title = "Козеріг";
$metatags['title'] = "".$title." > ".$timerus[$time] ." > ".$config['home_title']."";
break;
case "aquarius" :
$act = 11; $pic = "<img src=\"{THEME}/images/zodiac/aquarius.gif\" marginwidth=\"5\">";
$title = "Водолій";
$metatags['title'] = "".$title." > ".$timerus[$time] ." > ".$config['home_title']."";
break;
case "pisces" :
$act = 12; $pic = "<img src=\"{THEME}/images/zodiac/pisces.gif\" marginwidth=\"5\">";
$title = "Риби";
$metatags['title'] = "".$title." > ".$timerus[$time] ." > ".$config['home_title']."";
break;
}
if ($_GET['sign'] == "")
{
$sign = "aries";
$metatags['title'] = "".$title." > ".$timerus[$time] ." > ".$config['home_title']."";
}
else {
$sign = $_GET['sign'];
}
$hor = horos_cache($sign, $time.date(now));
if (!$hor) {
$open = @file_get_contents("http://horo.mail.ru/prediction.html?sign=$act&time=$time", "r");
if ($time == 'year') {
preg_match_all('|<div id="tm_year">(.*)<script|Uis', $open, $elements);
}
if ($time == 'month')
{
preg_match_all('|<div id="tm_month">(.*)<script|Uis', $open, $elements);
}
elseif ($time == 'week')
{
preg_match_all('|<div id="tm_week">(.*)<script|Uis', $open, $elements);
}
elseif ($time == 'yesterday')
{
preg_match_all('|<div id="tm_yesterday">(.*)<script|Uis', $open, $elements);
}
elseif ($time == 'tomorrow')
{
preg_match_all('|<div id="tm_tomorrow">(.*)<script|Uis', $open, $elements);
}
elseif ($time == '')
{
preg_match_all('|<div id="tm_today">(.*)?<script|Uis', $open, $elements);
}
foreach($elements[1] as $id=>$horoscope)
{
$hor .= $horoscope;
}
addto_cache($sign, $hor, $time.date(now));
}
if(isset($time) && $time != "")
{
if ($config['allow_alt_url'] == "yes")
{
$linkhor .= "<div align='center'><a href=\"/horo/$sign/\">Гороскоп на сьогодні</a><br></div>";
}
else
{
$linkhor .= "<div align='center'><a href=\"/index.php?do=horoscope&sign=$sign\">Гороскоп на сьогодні</a><br></div>";
}
}
else
{
if ($config['allow_alt_url'] == "yes")
{
$linkhor .= "<div align='center'><a href=\"/horo/$sign/tomorrow.html\">Гороскоп на завтра </a> | <a href=\"/horo/$sign/week.html\">Гороскоп на тиждень </a> | <a href=\"/horo/$sign/month.html\">Гороскоп на місяць </a> | <a href=\"/horo/$sign/year.html\">Гороскоп на рік</a></div>";
}
else
{
$linkhor .= "<div align='center'><a href=\"/index.php?do=horoscope&sign=$sign&time=tomorrow\">Гороскоп на завтра </a> | <a href=\"/index.php?do=horoscope&sign=$sign&time=week\">Гороскоп на тиждень </a> | <a href=\"/index.php?do=horoscope&sign=$sign&time=month\">Гороскоп на місяць </a> | <a href=\"/index.php?do=horoscope&sign=$sign&time=year\">Гороскоп на рік</a></div>";
}
}
if(!$hor)
{
$conhor .= "<br />Гороскоп на даний момент відсутній, зайдіть пізніше!";
}
if ($config['allow_alt_url'] == "yes")
{
$self_link = "<a href=\"/horo/\">Гороскоп</a>";
$blockhor .= '
<table width="100%" align="center"><tr width="100%" align="center"><td>
<A title="Овен (21.03 - 20.04)" href="/horo/aries/"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/aries.gif"></A><BR /><A title="Овен (21.03 - 20.04)" href="/horo/aries/">Овен</A>
<DIV>21.03 - 20.04</DIV>
</td><td>
<A title="Тілець (21.04 - 20.05)" href="/horo/taurus/"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/taurus.gif"></A><BR /><A title="Тілець (21.04 - 20.05)" href="/horo/taurus/">Тілець</A>
<DIV>21.04 - 20.05</DIV>
</td><td>
<A title="Близнюки (21.05 - 21.06)" href="/horo/gemini/"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/gemini.gif"></A><BR /><A title="Близнюки (21.05 - 21.06)" href="/horo/gemini/">Близнюки</A>
<DIV>21.05 - 21.06</DIV><br>
</td></tr><tr width="100%" align="center"><td>
<A title="Рак (22.06 - 22.07)" href="/horo/cancer/"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/cancer.gif"></A><BR /><A title="Рак (22.06 - 22.07)" href="/horo/cancer/">Рак</A>
<DIV>22.06 - 22.07</DIV>
</td><td>
<A title="Лев (23.07 - 23.08)" href="/horo/leo/"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/leo.gif"></A><BR /><A title="Лев (23.07 - 23.08)" href="/horo/leo/">Лев</A>
<DIV>23.07 - 23.08</DIV>
</td><td>
<A title="Діва (24.08 - 23.09)" href="/horo/virgo/"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/virgo.gif"></A><BR /><A title="Діва (24.08 - 23.09)" href="/horo/virgo/">Діва</A>
<DIV>24.08 - 23.09</DIV><br>
</td></tr><tr width="100%" align="center"><td>
<A title="Терези (24.09 - 23.10)" href="/horo/libra/"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/libra.gif"></A><BR /><A title="Терези (24.09 - 23.10)" href="/horo/libra/">Терези</A>
<DIV>24.09 - 23.10</DIV>
</td><td>
<A title="Скорпіон (24.10 - 22.11)" href="/horo/scorpio/"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/scorpio.gif"></A><BR /><A title="Скорпіон (24.10 - 22.11)" href="/horo/scorpio/">Скорпіон</A>
<DIV>24.10 - 22.11</DIV>
</td><td>
<A title="Стрілець (23.11 - 21.12)" href="/horo/sagittarius/"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/sagittarius.gif"></A><BR /><A title="Стрілець (23.11 - 21.12)" href="/horo/sagittarius/">Стрілець</A>
<DIV>23.11 - 21.12</DIV><br>
</td></tr><tr width="100%" align="center"><td>
<A title="Козеріг (22.12 - 20.01)" href="/horo/capricorn/"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/capricorn.gif"></A><BR /><A title="Козеріг (22.12 - 20.01)" href="/horo/capricorn/">Козеріг</A>
<DIV>22.12 - 20.01</DIV>
</td><td>
<A title="Водолій (21.01 - 20.02)" href="/horo/aquarius/"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/aquarius.gif"></A><BR /><A title="Водолій (21.01 - 20.02)" href="/horo/aquarius/">Водолій</A>
<DIV>21.01 - 20.02</DIV>
</td><td>
<A title="Риби (21.02 - 20.03)" href="/horo/pisces/"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/pisces.gif"></A><BR /><A title="Риби (21.02 - 20.03)" href="/horo/pisces/">Риби</A>
<DIV>21.02 - 20.03</DIV>
</td></tr></table>';
}
else
{
$self_link = "<a href=\"/index.php?do=horoscope\">Гороскоп</a>";
$blockhor .= '
<br>
<A title="Овен (21.03 - 20.04)" href="/index.php?do=horoscope&sign=aries"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/aries.gif"></A><BR /><A title="Овен (21.03 - 20.04)" href="/index.php?do=horoscope&sign=aries">Овен</A>
<DIV>21.03 - 20.04</DIV>
<br>
<A title="Тілець (21.04 - 20.05)" href="/index.php?do=horoscope&sign=taurus"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/taurus.gif"></A><BR /><A title="Тілець (21.04 - 20.05)" href="/index.php?do=horoscope&sign=taurus">Тілець</A>
<DIV>21.04 - 20.05</DIV>
<br>
<A title="Близнюки (21.05 - 21.06)" href="/index.php?do=horoscope&sign=gemini"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/gemini.gif"></A><BR /><A title="Близнюки (21.05 - 21.06)" href="/index.php?do=horoscope&sign=gemini">Близнюки</A>
<DIV>21.05 - 21.06</DIV>
<br>
<A title="Рак (22.06 - 22.07)" href="/index.php?do=horoscope&sign=cancer"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/cancer.gif"></A><BR /><A title="Рак (22.06 - 22.07)" href="/index.php?do=horoscope&sign=cancer">Рак</A>
<DIV>22.06 - 22.07</DIV>
<br>
<A title="Лев (23.07 - 23.08)" href="/index.php?do=horoscope&sign=leo"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/leo.gif"></A><BR /><A title="Лев (23.07 - 23.08)" href="/index.php?do=horoscope&sign=leo">Лев</A>
<DIV>23.07 - 23.08</DIV>
<br>
<A title="Діва (24.08 - 23.09)" href="/index.php?do=horoscope&sign=virgo"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/virgo.gif"></A><BR /><A title="Діва (24.08 - 23.09)" href="/index.php?do=horoscope&sign=virgo">Діва</A>
<DIV>24.08 - 23.09</DIV>
<br>
<A title="Терези (24.09 - 23.10)" href="/index.php?do=horoscope&sign=libra"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/libra.gif"></A><BR /><A title="Терези (24.09 - 23.10)" href="/index.php?do=horoscope&sign=libra">Терези</A>
<DIV>24.09 - 23.10</DIV>
<br>
<A title="Скорпіон (24.10 - 22.11)" href="/index.php?do=horoscope&sign=scorpio"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/scorpio.gif"></A><BR /><A title="Скорпіон (24.10 - 22.11)" href="/index.php?do=horoscope&sign=scorpio">Скорпіон</A>
<DIV>24.10 - 22.11</DIV>
<br>
<A title="Стрілець (23.11 - 21.12)" href="/index.php?do=horoscope&sign=sagittarius"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/sagittarius.gif"></A><BR /><A title="Стрілець (23.11 - 21.12)" href="/index.php?do=horoscope&sign=sagittarius">Стрілець</A>
<DIV>23.11 - 21.12</DIV>
<br>
<A title="Козеріг (22.12 - 20.01)" href="/index.php?do=horoscope&sign=capricorn"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/capricorn.gif"></A><BR /><A title="Козеріг (22.12 - 20.01)" href="/index.php?do=horoscope&sign=capricorn">Козеріг</A>
<DIV>22.12 - 20.01</DIV>
<br>
<A title="Водолій (21.01 - 20.02)" href="/index.php?do=horoscope&sign=aquarius"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/aquarius.gif"></A><BR /><A title="Водолій (21.01 - 20.02)" href="/index.php?do=horoscope&sign=aquarius">Водолій</A>
<DIV>21.01 - 20.02</DIV>
<br>
<A title="Риби (21.02 - 20.03)" href="/index.php?do=horoscope&sign=pisces"><IMG border="0" height="100" width="100" src="{THEME}/images/zodiac/pisces.gif"></A><BR /><A title="Риби (21.02 - 20.03)" href="/index.php?do=horoscope&sign=pisces">Риби</A>
<DIV>21.02 - 20.03</DIV>
<br>';
}
//echo $conhor;
$tpl->set('{timerus}',$timerus[$time]);
$tpl->set('{pic}',$pic);
$tpl->set('{zodiac}',$title);
$tpl->set('{blockhor}',$blockhor);
$tpl->set('{horoscope}',$hor);
$tpl->set('{links}',$linkhor);
$tpl->set('{self}',$self_link);
$tpl->compile('content');
$tpl->clear();
?>
Ответил: ravchik
найдите строку
и замените на
$open = @file_get_contents("http://horo.mail.ru/prediction.html?sign=$act&time=$time", "r");
и замените на
$open = iconv("UTF-8", "Windows-1251", @file_get_contents("http://horo.mail.ru/prediction.html?sign=$act&time=$time", "r"));