原創,PHP簡單的查詢火車時刻表程式

來源:互聯網
上載者:User
01.<?php

02.//利用別人的網站自己寫的一個查詢火車時刻表的小程式

03.if(isset($_POST['cx'])){

04.//拼字網址,測試能否順利開啟

05.$url = "http://wap.huoche.com.cn/chaxun/result.php?txtchufa=".$_POST['txtchufa']."&txtdaoda=".$_POST['txtdaoda']; //目標站

06.$fp = @fopen($url, "r") or die("逾時");

07.//抓取內容

08.$content=file_get_contents($url);

09.//處理內容

10.$str = $content;

11.$start = "<ul>";

12.$end = "</ul>";

13.function get_sub_content($str, $start, $end){

14.        if ( $start == '' || $end == '' ){

15.               return;

16.        }

17.        $str = explode($start, $str);

18.        $str = explode($end, $str[1]);

19.        return $str[0]; 

20.}

21.$row = get_sub_content($str, $start, $end);

22.//去掉a標籤

23.$out_a = str_ireplace("</a>","",preg_replace("/<a[^>]+>/", "", $row));

24.//去掉li標籤

25.$out_td = str_ireplace("</li>","",preg_replace("/<li[^>]+>/", "", $out_a));

26.//存放到數組

27.$over = explode('<li>', $out_td);

28.

29.}

30.?>

31.<form  method="post" > 

32.出發站:(漢字或拼音首字母)<br /> 

33.<input type="text" name="txtchufa" value="" /><br /> 

34.到達站:(例如:北京 或 BJ)<br /> 

35.<input type="text" id="to" name="txtdaoda" value="" /><br /> 

36.<input type="submit" name="cx" value="查詢" /> 

37.</form> 

38.<?if($over){?>

39.<table>

40.<?foreach($over as $key=>$value){?>

41.<tr>

42.<td><?=$value?></td>

43.</tr>

44.<?}?>

45.</table>

46.<?}?>

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.