Home  >  Article  >  Backend Development  >  车联网API php+xml (1) 景点查询

车联网API php+xml (1) 景点查询

WBOY
WBOYOriginal
2016-06-23 13:37:31950browse

<span style="font-size:18px;">view.html<form action="view.php" method="post">
<input type="text" name="view" value="景点的拼音"><input type="submit" name="submit" value="查看景点信息">
</form>view.php<?php #设置编码	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=0H6m5R2mBkUipA1zwDg0zBnG";				#获取信息		$data = file_get_contents($str);				#获取xml信息		$data = simplexml_load_string($data);		// 		var_dump($data);				#遍历景点信息		foreach($data->result as $val){			var_dump($val);			echo '<pre class="brush:php;toolbar:false">';			echo '景点名字:'.$val->name."<br>";			echo '景点介绍:'.$val->description."<br>";			echo '票价:'.$val->ticket_info->price."<br>";			echo '其它事项:'.$val->ticket_info->attention->item->description.'<br>';		}			}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn