php代码
<?php //采集反应时间设置 set_time_limit(0); //天气预报采集目标网址 杭州天气预报 $url = 'http://www.weather.com.cn/weather/101210101.shtml'; //实例化采集机器 $gather = new gather(); //获取目标网址HTML $html = $gather->geturlfile($url); //获取内容 $start = '<p class="weatherYubaoBox">'; $end = '<p id="weatherYubao2" class="weatherYubao">'; $content = $gather->get_sub_content($html, $start, $end); $text = substr(SpHtml2Text($content), 42); //载入飞信类(类自己到网上搜) require './lib/PHPFetion.php'; // 手机号、飞信密码 $fetion = new PHPFetion('xxxxxxxxxxx', 'xxxxxxxx'); //发送的号码,与天气预报信息 $fetion->send('18758056856', $text); echo 'ok!发送成功!'; /** * 采集类 */ class gather { public $pagestring = ''; private $db; function __construct() { global $db; $this->db = $db; } function geturlfile($url) { $url = trim($url); $content = ''; if (extension_loaded('curl')) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_HEADER, 0); $content = curl_exec($ch); curl_close($ch); } else { $content = file_get_contents($url); } return trim($content); } function s($code) { preg_match_all('/<a.+?href=["|\']?([^>"\' ]+)["|\']?\s*[^>]*>([^>]+)<\/a>/is', $code, $arr); return array('name' => $arr[2], 'url' => $arr[1]); } function get_sub_content($str, $start, $end) { $start = trim($start); $end = trim($end); if ($start == '' || $end == '') { return $str; } $str = explode($start, $str); $str = explode($end, $str[1]); return $str[0]; } function vd($var) { echo "<p style=\"border:1px solid #ddd;background:#F7F7F7;padding:5px 10px;\">\r\n"; echo "<pre style=\"font-family:Arial,Vrinda;font-size:14px;\">\r\n"; var_dump($var); echo "\r\n\r\n"; echo ""; } } //html转text function SpHtml2Text($str) { $str = preg_replace("/