Web服务用的是SOAP(简单对象访问协议):是web服务的通信协议,用来定义返回信息的xml格式的规范
技术 | 后缀 |
Asp | .asp |
php | .php |
.net(跨语言) | .aspx |
java | .jsp |
Wsdl:web服务描述语言,包括一系列web服务的定义。
注意:PHP默认不支持soap协议的,要在php.ini中开启soap协议
重启服务器
php利用xml调用国际航班
<?php
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
$client = new SoapClient('http://ws.webxml.com.cn/webservices/DomesticAirline.asmx?wsdl');
$city = $client->getDomesticCity()->getDomesticCityResult->any;
$simple = new SimpleXMLElement($city);
$addr_array = $simple->Airline1->Address;
?>
<form id="form1" name="form1" method="post" action="">
出发城市:
<select name="startCity" id="startCity">
<?php
foreach($addr_array as $row) :
?>
<option><?php echo $row->cnCityName; ?></option>
<?php
endforeach;
?>
</select>
到达城市:
<select name="lastCity" id="lastCity">
<?php
foreach($addr_array as $row) :
?>
<option><?php echo $row->cnCityName; ?></option>
<?php
endforeach;
?>
</select>
时间:<input type="text" name="theDate" value="<?php echo date('Y-m-d'); ?>" />
<input type="submit" name="button" id="button" value="提交" />
</form>
<?php
if(!empty($_POST)){
$startCity = $_POST['startCity'];
$lastCity = $_POST['lastCity'];
$theDate = $_POST['theDate'];
$param = array(
'startCity'=>$startCity,
'lastCity'=>$lastCity,
'theDate'=>$theDate,
'userId'=>''
);
$airline_str = $client->getDomesticAirlinesTime($param)->getDomesticAirlinesTimeResult->any;
$simple = new SimpleXMLElement($airline_str);
echo '<pre>';
$airline_array = $simple->Airlines->AirlinesTime;
?>
<table width="780" border="1" bordercolor="#000000" align="center">
<tr>
<th>航空公司</th>
<th>航班</th>
<th>出发机场</th>
<th>到达机场</th>
<th>起飞时间</th>
<th>到达时间</th>
<th>机型</th>
<th>停靠站</th>
<th>分型日期</th>
</tr>
<?php
foreach($airline_array as $airline) :
?>
<tr>
<th><?php echo $airline->Company; ?></th>
<th><?php echo $airline->AirlineCode; ?></th>
<th><?php echo $airline->StartDrome; ?></th>
<th><?php echo $airline->ArriveDrome; ?></th>
<th><?php echo $airline->StartTime; ?></th>
<th><?php echo $airline->ArriveTime; ?></th>
<th><?php echo $airline->Mode; ?></th>
<th><?php echo $airline->AirlineStop; ?></th>
<th><?php echo $airline->Week; ?></th>
</tr>
<?php
endforeach;
?>
</table>
<?php
}
?>
执行效果图:
php利用xml调用本地ip访问
<?php
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />';
$client = new SoapClient('http://ws.webxml.com.cn/WebServices/IpAddressSearchWebService.asmx?wsdl');
$Ip = $client->getGeoIPContext()->getGeoIPContextResult->string;
?>
<table width="780" border="1" bordercolor="#000000" align="center">
<tr>
<th>网址</th>
</tr>
<?php
foreach($Ip as $ip) :
?>
<tr>
<th><?php echo $ip; ?></th>
</tr>
<?php
endforeach;
?>
</table>
<?php
执行效果图: