PHP via API interface to connect 12,306 ticket query

Source: Internet
Author: User

<?PHPHeader("content-type:text/html;charset= ' Utf-8 '");//Set EncodingEcho"<meta content= ' text/html; Charset=utf-8 ' http-equiv= ' content-type ' > '; //get the information from the API Querydate time from_station departure number To_station arrival Station number$url= "Https://kyfw.12306.cn/otn/lcxxcx/query?purpose_codes=ADULT&queryDate=2016-09-31&from_station=GZQ &to_station=gaz "; //Get content content is in JSON format$data= GetContent ($url);functionGetContent ($url){//gets the output portion of the Web page and returns a string    $ch=Curl_init (); $timeout= 5; curl_setopt ($ch, Curlopt_url,$url); curl_setopt ($ch, Curlopt_returntransfer, 1); curl_setopt ($ch, Curlopt_ssl_verifyhost,FALSE); curl_setopt ($ch, Curlopt_ssl_verifypeer,FALSE); curl_setopt ($ch, Curlopt_connecttimeout,$timeout); $dxycontent= Curl_exec ($ch); Curl_close ($ch); return $dxycontent;}//transcoding$data= Json_decode ($data); //JSON transcoding is followed by an object that needs to be transferred to an array or it cannot be loopedfunctionObject_array ($array){    if(Is_object($array)){        $array= (Array)$array; }    if(Is_array($array)){        foreach($array  as $key=$value){            $array[$key] = Object_array ($value); }    }    return $array;}//Get Array Data$data 2= Object_array ($data);//Just a little bit of landscapingEcho' <table border= ' 1 "> ';Echo‘<tr><td> train </td><td> Departure/arrival/terminal </td><td> time of arrival </td><td> Duration </td><td> Business Seat </td><td> principal block </td> <td> class </td& </td><td> second seat Gt;<td> Advanced soft sleeper </td><td> soft sleeper </td><td> hard sleeper </td><td> soft seat </td><td> hard seat </td> <td> no seat </td><td> other </td><td> remarks </td></tr>‘;//Loopsforeach($data 2[' Data '] [' Datas '] as $k=$v){    Echo' <tr><td> '.$v[' Station_train_code ']. ' </td><td> '.$v[' Start_station_name ']. ' '.$v[' To_station_name ']. ' '.$v[' End_station_name ']. ' </td><td> '.$v[' Start_time ']. ' / ‘.$v[' Arrive_time ']. ' </td><td> '.$v[' Lishi ']. ' </td><td> '.$v[' Swz_num ']. ' </td><td> '.$v[' Tz_num ']. ' </td><td> '.$v[' Zy_num ']. ' </td><td> '.$v[' Ze_num ']. ' </td><td> '.$v[' Gr_num ']. ' </td><td> '.$v[' Rw_num ']. ' </td><td> '.$v[' Yw_num ']. ' </td><td> '.$v[' Rz_num ']. ' </td><td> '.$v[' Yz_num ']. ' </td><td> '.$v[' Wz_num ']. ' </td><td> '.$v[' Qt_num ']. ' </td><td> '.$v[' Note ']. ' </td></tr> ';}Echo' </table> ';/** ["gr_num"]=> advanced soft Sleeper * ["Qt_num"]=> Other * ["rw_num"]=> soft sleeper * ["rz_num"]=> soft seat * ["Tz_num"]=> principal block * ["Wz_num"]=> no seat * ["Yw_num"]=> hard Sleeper * ["yz_num"]=> hard seat * ["Ze_num"]=> Second class * ["Zy_num"]=> * * ["Swz_nu M "]=> Business seat*/

PHP via API interface to connect 12,306 ticket query

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.