Original, simple PHP Train Timetable query Program

Source: Internet
Author: User
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. <?}?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.