原创,PHP简单的查询火车时刻表程序

来源:互联网 发布:java tcp监听端口 编辑:程序博客网 时间:2024/04/23 18:05
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.<?}?>
原创粉丝点击