php获取用户浏览器、操作系统、本地天气

2014-05-24 12:24:43

[php]

ret == 1) {  
 if ($info ->province != $info ->city) {  
 return $info ->country.",".$info ->province."(".$info ->city.") ".$info ->district." ".$info ->desc;  
 } else {  
 return $info ->country.",".$info ->province." ".$info ->district." ".$info ->desc;  
 }  
 } else {  
 return ‘地球’;  
 }  
 }

// 复杂获取本地ip地址  
 /* if (getenv(‘HTTP_CLIENT_IP’) && strcasecmp(getenv(‘HTTP_CLIENT_IP’), ‘unknown’)) {  
 $SA_IP = getenv(‘HTTP_CLIENT_IP’);  
 } elseif (getenv(‘HTTP_X_FORWARDED_FOR’) && strcasecmp(getenv(‘HTTP_X_FORWARDED_FOR’), ‘unknown’)) {  
 $SA_IP = getenv(‘HTTP_X_FORWARDED_FOR’);  
 } elseif (getenv(‘REMOTE_ADDR’) && strcasecmp(getenv(‘REMOTE_ADDR’), ‘unknown’)) {  
 $SA_IP = getenv(‘REMOTE_ADDR’);  
 } elseif (isset($_SERVER[‘REMOTE_ADDR’]) && $_SERVER[‘REMOTE_ADDR’] && strcasecmp($_SERVER[‘REMOTE_ADDR’], ‘unknown’)) {  
 $SA_IP = $_SERVER[‘REMOTE_ADDR’];  
 } */  
 $SA_IP=$_SERVER[‘REMOTE_ADDR’];//简单获取本地ip地址  
 //定义一个函数根据ip获取城市名,使用新浪的天气预报  
 function getIPLoc_sina($queryIP){  
 $url = ‘http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=’ . $queryIP;  
 $ch = curl_init($url);  
 curl_setopt($ch, CURLOPT_ENCODING, ‘utf8’);  
 curl_setopt($ch, CURLOPT_TIMEOUT, 10);  
 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);  
 $location = curl_exec($ch);  
 $location = json_decode($location);  
 curl_close($ch);  
 $loc = "";  
 if ($location === FALSE)  
 return "";  
 if (empty($location->desc)) {  
 $loc = $location->city;  
 $full_loc = $location->province . $location->city . $location->district . $location->isp;  
 } else {  
 $loc = $location->desc;  
 }  
 return $loc;  
 }  
 $city = getIPLoc_sina("$SA_IP");

$citycode = mb_convert_encoding($city, "gb2312", "utf-8");

$doc = new DOMDocument();  
 if (!@$doc->load("http://php.weather.sina.com.cn/xml.php?city=" . $citycode . "&password=DJOYnieT8234jlsK&day=0")) {  
 echo "Get data failed!!\n";  
 return;  
 }

$city = $doc->getElementsByTagName("city")->item(0)->nodeValue;  
 $stat1 = $doc->getElementsByTagName("status1")->item(0)->nodeValue;  
 $chy_shuoming = $doc->getElementsByTagName("chy_shuoming")->item(0)->nodeValue;  
 $tmp1 = $doc->getElementsByTagName("temperature1")->item(0)->nodeValue;  
 $tmp2 = $doc->getElementsByTagName("temperature2")->item(0)->nodeValue;  
 $date = $doc->getElementsByTagName("savedate_weather")->item(0)->nodeValue;  
 $pollution_l = $doc->getElementsByTagName("pollution_l")->item(0)->nodeValue;  
 $gm_s = $doc->getElementsByTagName("gm_s")->item(0)->nodeValue;

echo "我猜你用的浏览器是:".browser($useragent);  
 echo "
我猜你的电脑操作系统是:".os($useragent); echo"
我猜你来自:".address($_SERVER[‘REMOTE_ADDR’]); echo "
我猜今天是:" .$date . "
我猜今天的天气是:". $tmp1 ."~". $tmp2 ."℃" .$stat1 ."
我猜空气质量:".$pollution_l ."
我建议你穿这些:". $chy_shuoming ; echo "
以上信息仅供参考!!请勿当真!!如有雷同,纯属巧合!!" ?>

[/php]

浅析JS和PHP中等于(==)和恒等(===)的区别

首先,先做个简单的介绍,让先有个直观的认识 equality 等同     = identity 恒等  两边值类型不同的时候,要先进行类型转换,再比较。 = 不做类型转换,类型不同的一定不等。 举例说明: “1”    true 类型不同,””将先做类型转换,把true转换为1,即为 “1”    1; 此时,类型仍不同,继续进行类型转换,把”1″转换为1,即为 1 1; 此时,”” 左右两边的类型都为数值型,比较成功! 如果比较:”1″  =  true 左侧为字符型,右侧为bool布尔型,左右两侧类型不同,结果为false; 如果比较:”1″  =  1      左侧为字符型,右侧为int数值型,左右两侧类型不同,结果为false; 如果比较: 1   =  1

正则去掉<a>标签并保留标签内容

话不多说,直接上例子: [php] $str = " www.ldsun.com "; $str1 = pregreplace("/]*>/","", $str); $str2 = pregreplace("/<\/a>/","", $str1); echo $str2; [/php]