01. <? PHP
02. // use a small program written by someone else's website to query train schedules
03. If (isset ($ _ post ['cx ']) {
04. // spell the URL to test whether the URL can be opened successfully
05. $ url = "http://wap.huoche.com.cn/chaxun/result.php? Txtchufa = ". $ _ post ['txtchufa ']." & txtdaoda = ". $ _ post ['txtdaoda']; // target site
06. $ fp = @ fopen ($ URL, "R") or die ("timeout ");
07. // capture content
08. $ content = file_get_contents ($ URL );
09. // process content
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. // remove the tag
23. $ out_a = str_ireplace ("</a>", "", preg_replace ("/<A [^>] +>/", "", $ row ));
24. // remove the Li tag
25. $ out_td = str_ireplace ("</LI>", "", preg_replace ("/<li [^>] +>/", "", $ out_a ));
26. // store it in an array
27. $ over = explode ('<li>', $ out_td );
28.
29 .}
30.?>
31. <form method = "Post">
32. Departure Site: (first letter of Chinese character or pinyin) <br/>
33. <input type = "text" name = "txtchufa" value = ""/> <br/>
34. arrival site: (for example, Beijing or BJ) <br/>
35. <input type = "text" id = "to" name = "txtdaoda" value = ""/> <br/>
36. <input type = "Submit" name = "CX" value = "query"/>
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. <?}?>