Improved auto Show Weather Report applet (both Linux and Windows environments can)
Last Update:2017-02-28
Source: Internet
Author: User
window| Program | weather Forecast | This improvement is mainly to increase the image acquisition, and provide a relatively complete function to get the remote file. The specific code is as follows:
?
$fcont =file ("http://www.bjmb.gov.cn/today.asp");
$arr =array ();
for ($i =0; $i <count ($fcont); $i + +) {
$tmp = $fcont [$i];
$tmp =ereg_replace ("<br>", "", $tmp);
if (!strstr (Strtolower ($tmp), "img")) {
$tmp =trim (Strip_tags ($tmp));
} else {
$st =ereg_replace ("><", ">⌒<", $tmp);
$stt =split ("⌒", $st);
foreach ($stt as $key => $value) {
if (Strstr ($value, "img")) {
$tmp = $value;
if (Strstr ($tmp, "bt9.jpg") | | strstr ($TMP, "Colline.gif")) {
$tmp = "";
}else{
$tmp =ereg_replace ("\" "," ", $tmp);
$st =split ("src=", $tmp);
$st 1=split ("", $st [1]); Getpic ("http://www.bjmb.gov.cn/$st 1[0]", "image");
if (count ($st) >2) {
$st 2=split ("", $st [2]); Getpic ("http://www.bjmb.gov.cn/$st 1[0]", "image");
}
$tmp =ereg_replace ("src=", "width=30 height=30 align=absmiddle src=", $tmp);
}
}
}
}
if (Trim ($tmp)!= "" && trim ($tmp)!= "") $arr []= $tmp;
}
$yb =array ();
For ($i =2 $i <count ($arr)-6; $i + +) {
$yb []= $arr [$i];
}
?>
<br>
<script language= "JavaScript" >
<!--
Syb= "";
?
$exp = " -3-7-9-14-18-20-25-";
for ($i =1; $i <count ($YB); $i + +) {
if (!strstr ($exp, "-". String) ($i + 1). " -")){
?>
syb=syb+ ' <?= $yb [$i];? > ';
;?}}? >
document.write ("<?= $yb [0]?>" + ":");
document.write ("<marquee width=400 align=middle scrollamount=5 scrolldelay=200>" +syb+ "forecast </marquee>");
-->
</SCRIPT>
?
function Getpic ($url, $dir) {
$tmp =split ("/", $url);
$fname = $tmp [Count ($tmp)-1];
if (Strstr ($dir, "\ \")) {
if (substr ($dir, -2) = = "\") $file = $dir. $fname; else $file = $dir. " \ ". $fname;
}else{
if (substr ($dir, "/")) {
if (substr ($dir, -1) = = "/") $file = $dir. $fname; else $file = $dir. " /". $fname;
}
else{
return;
}
}
if (!) ( File_exists ("$dir") && is_dir ("$dir")) mkdir ($dir, 0777);
if (file_exists ($file)) return;
$fpo =fopen ($file, "WB");
if (! $fpo) return;
$num = 0;
do{
$num + +;
$FPI =fopen ($url, "R");
}while (! $FPI && $num <3);
if (!FPI) return;
while (!feof ($FPI)) {
$cont =fread ($FPI, 128);
Fwrite ($fpo, $cont, 128);
}
Fclose ($FPI);
Fclose ($FPO);
}
?>