<?php header('Content-Type:text/html;charset=utf-8'); if($_GET['sub']){ $ip = $_GET['ip']; $msg = ''; ipSearch(); } function ipSearch(){ global $ip,$msg; if(!$ip){ $msg = '請至少填寫一個ip!'; return; } $arises = substr_count($ip,'.'); $long = ip2long($ip); if($arises != 3 || $long == false || $long== -1){ $msg = '無效ip地址,請重新輸入!'; return; } $content = file_get_contents('http://www.ip138.com/ips1388.asp?action=2&ip='.$ip); $content = iconv('gb2312', 'utf-8', $content); $pos = stripos($content, '<li>本站主數據'); if(!$pos){ $msg = '沒有查詢到!'; return; } $endPos = stripos($content, '</li>', $pos); $jumpLen = strlen('<li>本站主數據:'); $address = substr($content, $pos+$jumpLen, $endPos-$pos-$jumpLen); $msg = $address; return; } ?><!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>test</title> </head> <body> <form method="get"> <input type="text" name="ip" /> <input type="submit" value="search" name="sub" /> </form><br /> <?php echo $msg; ?> </body> </html>
查看本欄目