网站地图    收藏   

主页 > 后端 > 微信开发 >

方倍微信公众平台开发(63)汽车查询 - 微信公众

来源:自学PHP网    时间:2015-04-14 12:58 作者: 阅读:

[导读] 微信公众平台开发 微信公众平台开发模式 企业微信公众平台汽车查询作者:方倍工作室地址:http: www cnblogs com txw1958 p weixin-63-coach html核心代码:?phpinclude( simple_html_dom php );...

 核心代码:

 

<?php

include('simple_html_dom.php');

// var_dump(getCoachInfo("广州到深圳"));
function getCoachInfo($keyword)
{
    $divide = "到";
    $dividePos = strpos($keyword, $divide);
    $divideLen = strlen($divide);
    $from = substr($keyword, 0, $dividePos);
    $to = substr($keyword, $dividePos + $divideLen, strlen($keyword) - $dividePos - $divideLen);

    try {
        $url = "http://www.keyunzhan.com/zhandaozhan_search.php?find_type=2&shousuo=2&startstate=".urlencode($from)."&endstate=".urlencode($to);
        $html_coach = file_get_html($url);
        if (!isset($html_coach)){
            $html_coach->clear();
            return "检索出错!\n如果经常这样,请发送9到QQ空间给我们留言。";
        }
       
        $result = "";
        foreach($html_coach->find('div[class="car_left_detail01_rows"]') as $singleCoach) {
            $start = $singleCoach->find('div[class="car_left_detail01_rows_col01"]', 0)->plaintext;
            $station    = $singleCoach->find('div[class="car_left_detail01_rows_col01"]', 1)->plaintext;
            $end        = $singleCoach->find('div[class="car_left_detail01_rows_col01"]', 2)->plaintext;
            $time       = $singleCoach->find('div[class="car_left_detail01_rows_col02"]', 0)->plaintext;
            $time2      = trim(str_replace("+显示全部", "",$time));
            $time3      = preg_replace("/[\n\s]+/is", " ", $time2);
            $distance   = $singleCoach->find('div[class="car_left_detail01_rows_col02"]', 1)->plaintext;
            $price      = $singleCoach->find('div[class="car_left_detail01_rows_col03"]', 0)->plaintext;
            
            $result .= "出发:".$start.$station."\n".
                       "目的:".$end."\n".
                       "时间:".$time3."\n".
                       "里程:".$distance."\n".
                       "票价:".$price."\n\n";
        }

        $html_coach->clear();
        return trim($result);
    }catch (Exception $e){

    }
}

?>

 

演示图片

 

\\

自学PHP网专注网站建设学习,PHP程序学习,平面设计学习,以及操作系统学习

京ICP备14009008号-1@版权所有www.zixuephp.com

网站声明:本站所有视频,教程都由网友上传,站长收集和分享给大家学习使用,如由牵扯版权问题请联系站长邮箱904561283@qq.com

添加评论