<span style= "color: #993399;" > #html页面 Submit Query Information view.html</span><body><form action= "view.php" method= "post" ><input type= ' Text ' name= ' view ' value= ' Pinyin ' ><input type= "submit" name= "Submit" value= "View attractions Information" ></form><span style= "COLOR: #993399;" >view.php page for XML processing </span><?php# set coded header (' Content-type:text/html;charset=utf-8 '); #判断接收数据if (Isset ( $_post[' Submit ']) {#接收景点拼音 $view = $_post[' view '); #使用接口 $str = "Http://api.map.baidu.com/telematics/v3/travel_ attractions?id={$view}&ak=<span style= "color: #993399;" >0H6m5R2mBkUipA1zwDg0zBnG</span> "; #该密匙在百度libs云注册后获得 # Get information $data = file_get_contents ($STR); #获取xml信息 $data = simplexml_load_string ($data); <span style= " Color: #993399; " > #遍历景点信息 parsing according to the XML structure of the </span>foreach ($data->result as $val) {var_dump ($val); Echo ' <pre> '; echo ' Attraction name: '. $val->name. " <br> "Echo ' Attractions Description: '. $val->description." <br> "; Echo ' fare: '. $val->ticket_info->price." <br> "; echo" Other matters:'. $val->ticket_info->attention->item->description. ' <br> ';}}
Php+simplexml Car Networking API usage (1) Attractions Enquiry