Common website modules may include registration, login, posting, comments, and comments. The most important thing is to obtain IP addresses and process data. If you build your own IP database to occupy resources and the update is inconvenient, why not use a ready-made IP address for query? Next I wrote a PHP code to obtain the IP address's physical address.Code(Please kindly advise me if you have any flaws)
<! Doctype html >
< HTML Lang = " En " >
< Head >
< Title > </ Title >
< Meta charset = " UTF-8 " />
< Meta name = " Author " Content = "" />
< Meta name = " Keywords " Content = "" />
< Meta name = " Description " Content = "" />
</ Head >
< Body >
<? PHP
$ Ipaddr = " 218.75.124.100 " ;
$ Ip138addr = " Http://www.ip138.com/ips8.asp? IP = " . $ Ipaddr . " & Amp; Action = 2 " ;
$ Contents = File_get_contents ( $ Ip138addr );
$ Pattern = " /\ <Li. +? \/Li \>/ " ;
$ String = $ Contents ;
Preg_match_all ( $ Pattern , $ String , $ Addrarray );
$ Num = Count ( $ Addrarray [ 0 ]);
For ( $ I = 0 ; $ I < $ Num ; $ I ++ ){
Echo $ Addrarray [ 0 ] [ $ I ] = Mb_convert_encoding ( $ Addrarray [ 0 ] [ $ I ] , " UTF-8 " , " Gb2312 " );
Switch ( $ I ){
Case 0 : $ Str = " <Li> master data of this site: </LI> " ; Break ;
Case 1 : $ Str = " <Li> reference data 1: </LI> " ; Break ;
Case 2 : $ Str = " <Li> reference data 2: </LI> " ; Break ;
Case 3 : $ Str = " <Li> reference data 3: </LI> " ; Break ;
Case 4 : $ Str = " <Li> reference data 4: </LI> " ; Break ;
Case 5 : $ Str = " <Li> reference data 6: </LI> " ; Break ;
Case 6 : $ Str = " <Li> reference data 7: </LI> " ; Break ;
}
$ Addrarray [ 0 ] [ $ I ] = Trim ( $ Addrarray [ 0 ] [ $ I ] , $ Str );
}
$ Addrarray [ 0 ] [ 0 ] = Trim ( $ Addrarray [ 0 ] [ 0 ] , " : " );
Echo " <PRE> " ;
Print_r ( $ Addrarray );
Echo " </PRE> " ;
?>
</ Body >
</ Html >
This Code uses access to the http://www.ip138.com using a regular expression to intercept part of the content, where the regular expression is self-written.
Fortunately, the following processing results contain garbled characters. If $ STR (the first and last character of the string is removed) is defined, no garbled characters are found. In addition, a separate ": "statement, you can achieve the phenomenon of no garbled, do not know why ......