When I first started learning PHP, I first compiled a program and placed it on my home page to display the weather forecast. Of course, it is still not perfect. I hope you can give me some comments. The procedure 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 ("> <", "> replace <", $ tmp );
$ Stt = split ("shard", $ st );
Foreach ($ stt as $ key => $ value ){
If (strstr ($ value, "img ")){
$ Tmp = $ value;
$ Tmp = ereg_replace ("src =", "width = 30 height = 30 align = absmiddle src =", $ tmp );
If (strstr ($ tmp, "bt9.jpg") | strstr ($ tmp, "colline.gif") $ 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 + "prediction </marquee> ");
// -->
</SCRIPT>
The previously obtained statement only needs to be executed once. Then, compare the obtained data with the old data to determine whether it is new. If it is new, replace the old data. Otherwise, do not replace it. This is a regular search. First, judge the time. Generally, if it is one hour later than the forecast time, you can certainly get the latest forecast data. But now I have not considered that much. Let's talk about it later!