Яндекс погода. Из ANSI в UTF-8

1 23
Olldman
На сайте с 21.04.2010
Offline
79
#21

Да замените вы его принудительно:

$temp[1] = str_replace("в€’","–",$temp[1]);

И, кстати, город и weather_type отдается также в кодировке utf-8

http://realtsib.ru/oldman/yandex_pogoda.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=windows-1251">
<title></title>
<style type="text/css">
body{font:14px Arial;}
h1{font-size:16px;}
ul{list-style:none;}
</style>
</head>
<body>
<?php
$pogoda = file_get_contents('http://export.yandex.ru/weather/?city=28698');
preg_match('/<day>(.*?)<\/day>/i',$pogoda,$day);
preg_match('/<month>(.*?)<\/month>/i',$pogoda,$month);
preg_match('/<year>(.*?)<\/year>/i',$pogoda,$year);
preg_match('/<city>(.*?)<\/city>/i',$pogoda,$city);
$city[1] = iconv('UTF-8','CP1251',$city[1]);
preg_match('/<temperature>(.*?)<\/temperature>/i',$pogoda,$temp);
$temp[1] = str_replace("в€’","–",$temp[1]);
preg_match('/<image>(.*?)<\/image>/i',$pogoda,$image);
preg_match('/<weather_type>(.*?)<\/weather_type>/i',$pogoda,$weather_type);
$weather_type[1] = iconv('UTF-8','CP1251',$weather_type[1]);
$vivod ='';
$vivod.= "<h1>г. $city[1], $day[1].$month[1].$year[1]</h1>\n";
$vivod.= "<ul>\n";
$vivod.= "<li>".$temp[1]." ° <img src=\"$image[1]\" alt=\"$weather_type[1]\" title=\"$weather_type[1]\"></li>\n";
$vivod.= "</ul>\n";
print $vivod;
?>

</body>
</html>
newseditor
На сайте с 13.11.2006
Offline
123
#22

Olldman, в моем случае именно Ваша помощь оказалась реальной. Большое спасибо!

1 23

Авторизуйтесь или зарегистрируйтесь, чтобы оставить комментарий