Daily Archive for October 10th, 2008

Lấy bảng dự báo thời tiết

Dễ lắm :D Ngày xửa ngày xưa thì dùng đoạn Javascript của bên Vnexpress.net. Nhưng giờ ít ai dùng cái đó nữa vì nó quá đơn giản. Thế nên sẽ lấy ở các nguồn khác thôi. Chung quy lại, là nên lấy của thằng Trung tâm khí tượng thủy văn Việt Nam (http://www.nchmf.gov.vn) là chuẩn nhất (chuyện, của Việt Nam mà :p)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/**
* Get weather table
* @author Do Nam Khanh 
* @return string
*/
function _weather() {
	$content = file_get_contents('http://www.nchmf.gov.vn/website/vi-VN/43/Default.aspx');
 
	$strBegin 	= '<!-- Begin Display content -->';
	$strEnd 	= '<TD class="thoitiet_rightbox_ver"></TD>';
 
	$pos1 = strpos($content, $strBegin);
 
	if(false === $pos1) {
		return '';
	}
	else {
		$pos2 = strpos($content, $strEnd);
		$content = substr($content, $pos1, ($pos2-$pos1));
		return strip_tags($content, '<table><tr><td><img>');
	}
}

Demo: http://halongtours.vn/demo

[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]