文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>【原创】PHP获取新浪天气数据

【原创】PHP获取新浪天气数据

时间:2010-08-26  来源:wgw8299

第一次在博客园发文章。没有内容,直接上代码;如下:

 1 <?php
2 /**
3 * 获取新浪天气数据
4 *
5 * Project: Product Library Management System
6 * This is NOT a freeware, use is subject to license terms
7 *
8 * Site: http://www.cnblogs.com/wgw8299
9 *
10 * $Id: index.php 241 2009-11-30 00:14:01 wgw8299 $
11 *
12 * Copyright (C) 2008-2009 Reachone Dev Team. All Rights Reserved.
13 */
14
15
16 /**
17 * 获取URL地址内容
18 *
19 * @param string $url 地址
20 *
21 * @return mixed
22 */
23 function getUrlContent($url) {
24
25 $url_parsed = parse_url($url);
26 $host = $url_parsed['host'];
27 $port = $url_parsed['port'];
28
29 /* Port */
30 if ( $port == 0 ) {
31 $port = 80;
32 }
33
34 /* Path */
35 $path = $url_parsed['path'];
36 if (empty($path)) {
37 $path = "/";
38 }
39
40 /* query */
41 if ( $url_parsed['query'] != "" ) {
42 $path .= "?".$url_parsed['query'];
43 }
44
45 /* Open Page Content */
46 $out = "GET {$path} HTTP/1.0\r\nHost: {$host}\r\n\r\n";
47 if ($fp = @fsockopen( $host, $port, $errno, $errstr, 30 )) {
48 fwrite($fp,$out);
49 $body = false;
50 while (!feof($fp)) {
51 $s = fgets($fp,1024);
52 if ($body) {
53 $in .= $s;
54 }
55 if ( $s == "\r\n" ) {
56 $body = true;
57 }
58 }
59 fclose($fp);
60 return $in;
61 } else {
62 return false;
63 }
64 }
65
66 /* 生成JS代码 */
67 $conttent = getUrlContent("http://php.weather.sina.com.cn/search.php?city=独山&c=1&dpc=1");
68 preg_match_all('/javascript:sent_to_vb(.*)i6/isU', $conttent, $match_img);
69
70 $var = explode("'" , $match_img[1][0]);
71 echo "document.write('". $var[3] . "');\n";
72 ?>
73
74

 

相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载