Home  >  Article  >  php教程  >  PHP获取ip对应地区

PHP获取ip对应地区

PHP中文网
PHP中文网Original
2016-05-25 17:13:191036browse

跳至

  /**
  * 获取IP地区
  * Enter description here ...
  * @param unknown_type $ip
  */
 function GetArea($ip){

	$url = "http://ip168.com/ip/?ip=".$ip;
	$contents = file_get_contents($url);
//	preg_match_all(&#39;/<h3[\s\S]*?(<a[\s\S]*?)/&#39;,$contents,$rs);
	preg_match_all(&#39;|本站主数据:.*|&#39;,$contents,$rsR);
	$rsR[0][0] = str_replace("本站主数据:", "", $rsR[0][0]);
	$rsR[0][0] = str_replace("", "", $rsR[0][0]);
	return $rsR[0][0];
 }

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn