㈠ php如何用soap傳遞xml
請參考:開源中國社區里邊的這邊文章:
php調用web services兩種方法soap and xml-rpc
連接:my.oschina.net/adamboy/blog/29569
㈡ php如何傳送xml文件或者數據
使用fopen 或者file_get_contents等進行遠程獲取。
㈢ php輸出xml內容
PHP生成XML的方法很多,這里演示最基本,最簡單的字元串構造法。就是使用字元串構造或者拼接成xml數據格式,然後輸出或者生成xml文件。
<?php
$data=array(
array(
'title'=>'',
'country'=>'china',
'name'=>'網路',
),
array(
'title'=>'google',
'country'=>'usa',
'name'=>'谷歌',
)
);
//構造xml數據格式
$xml="<?xmlversion="1.0"encoding="utf-8"?> ";
$xml.="<data> ";
foreach($dataas$itm){
//循環構造xml單項
$item="<item> ";
$item.="<title>".$itm['title']."</title> ";
$item.="<country>".$itm['country']."</country> ";
$item.="<name>".$itm['name']."</name> ";
$item.="</item> ";
$xml.=$item;
}
$xml.="</data> ";
//輸出xml數據
echo$xml;
?>
生成的數據格式如下:
㈣ php如何調用xml文件
推薦用simpleXML處理xml,舉例如下:
$xml=simplexml_load_file('http://www.w3schools.com/xml/plant_catalog.xml');
foreach($xml->PLANTas$plantNode){
echo$plantNode->COMMON,'-',$plantNode->PRICE," ";
}
㈤ php 如何發送xml報文
<?php
if($_SERVER['REQUEST_METHOD']==='POST'){
//接收
$content=file_get_contents('php://input');
$xml=simplexml_load_string($content);
echo"來自XML接收方的響應 ";
print_r(get_object_vars($xml));
exit;
}
//發送行為
$xml=<<<xml
<?xmlversion="1.0"?>
<FOX>
<hello>world</hello>
</FOX>
xml;
$setting=array(
'http'=>array(
'method'=>'POST',
'user_agent'=>'<ClientApplicationName>',
'header'=>"Content-type:application/x-www-form-urlencoded",
'content'=>$xml
)
);
$context=stream_context_create($setting);
$url='http://localhost/'.$_SERVER['REQUEST_URI'];
$response=file_get_contents($url,null,$context);
echo$response;
CURL是可以的,但是參數設置比較麻煩。這種情況有一些現成的類庫實現,提供一個簡單的示例
㈥ PHp怎麼獲取網路傳過來的xml文件
<?php
$xml_string=file_get_contents("php://input");
$xml_string=trim($xml_string);
$xml_object=simplexml_load_string($xml_string);
$xml_arr=get_object_vars($xml_object);
只要別人訪問你這個文件傳遞xml。你就能獲取其中的信息了。
㈦ php如何通過xml傳遞數據
獲取request中body的字元串數據,比如一個數組轉成xml後,你用post方式給伺服器發送xml的字元串,伺服器就用file_get_contents('php://input') 去讀取xml格式 然後轉成數組即可
㈧ php 從資料庫裡面讀取數據後怎麼寫成xml傳輸
用PHP讀取資料庫中的數據 - >輸出XML文檔 - >在Flash中載入XML
㈨ php如何post XML到指定伺服器
以下是一個編寫好的postXML的類:
<?php
classxmlSender{
/**
*構造器
*校驗cURL是不是可用
*/
functionxmlSender()
{
if(!extension_loaded('curl')){
trigger_error("",E_USER_ERROR);
}
}
/**
*使用了cURL庫發送xml內容
*/
functionsend($str_xml,$str_url,$str_page,$boo_ssl=false)
{
$str_header="POST".$str_page."HTTP/1.0 ";
$str_header.="MIME-Version:1.0 ";
$str_header.="Content-type:application/PTI26 ";
$str_header.="Content-length:".strlen($str_xml)." ";
$str_header.="Content-transfer-encoding:text ";
$str_header.="Request-number:1 ";
$str_header.="Document-type:Response ";
$str_header.="Interface-Version:Site1.0 ";
$str_header.="Connection:close ";
$str_header.=$str_xml;
$res_curl=curl_init();
curl_setopt($res_curl,CURLOPT_URL,$str_url);
curl_setopt($res_curl,CURLOPT_RETURNTRANSFER,1);
curl_setopt($res_curl,CURLOPT_TIMEOUT,30);
curl_setopt($res_curl,CURLOPT_CUSTOMREQUEST,$str_header);
curl_setopt($res_curl,CURLOPT_FOLLOWLOCATION,1);
if($boo_ssl){
curl_setopt($res_curl,CURLOPT_SSL_VERIFYHOST,0);
curl_setopt($res_curl,CURLOPT_SSL_VERIFYPEER,false);
}
$str_data=curl_exec($res_curl);
if(curl_errno($res_curl)){
trigger_error(curl_error($res_curl),E_USER_ERROR);
}else{
curl_close($res_curl);
}
return$str_data;
}
}
$str_xml='<xxx>blablabla</xxx><yyy>blebleble</yyy><zzzz>bliblibli</zzz>';
$o=newxmlSender;
print_r($o->send($str_xml,"https://endereco.com.br/","/yyy/x.x.x/",true));
?>
=========================================
這幾天我正在研究cURL,這個庫正好能夠完成你的需要,具體代碼的編寫需要示例數據與網站才能測試,以下是post的示例:
<?php
$url='http://www.example.com/submit.php';
//Thesubmittedformdata,encodedasquery-string-style
//name-valuepairs
$body='monkey=uncle&rhino=aunt';
$c=curl_init($url);
curl_setopt($c,CURLOPT_POST,true);
curl_setopt($c,CURLOPT_POSTFIELDS,$body);
curl_setopt($c,CURLOPT_RETURNTRANSFER,true);
$page=curl_exec($c);
curl_close($c);
?>
㈩ php輸出xml文件應該如何寫
最簡單的辦法就是拼湊:
echo '<?xml version="1.0" encoding="utf-8" ?>';
echo '<skplyaer>';
ech ...
echo '</ckplayer'>;