<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>'; echo '景点名字:'.$val->name."<br>"; echo '景点介绍:'.$val->description."<br>"; echo '票价:'.$val->ticket_info->price."<br>"; echo '其它事项:'.$val->ticket_info->attention->item->description.'<br>'; } }</span>
原文地址:http://blog.csdn.net/u010657348/article/details/44805063