php 生成xml字符串,PHP解析返回的XML字符串

项目中应用到了PHP接收XML,以前没有接触过这块所以这里小记一下上代码:protected function     getCustomerUserId( $username ){// 载入 nusoap库$this->load->library('Nusoap_lib');$api_url  =  "http://*****/interface/ucenter/usercenterinterface.php?wsdl";   //远程服务器接口地$this->nusoap_client = new nusoap_client( $api_url ,true );$this->nusoap_client->soap_defencoding     = 'utf-8';$this->nusoap_client->decode_utf8         = false;$this->nusoap_client->xml_encoding         = 'utf-8';$fieldxml   = 'id,username';$wherexml   = ''.$username.'';//  以上是通过PHP的NUSOAP组建调用webservice接口, 这里一并贴出来了,//    真正的解析方法就下面几行$parameters = array(    'field_xml'     => $fieldxml,'where_xml'        => $wherexml,'order_xml'        => 'asc','type'            => 'all','siteflag'         => 'phptest','pkey'             => md5('phptestphptest'),'cs'             => 'utf-8');// 创建DOM 文档$xml = new DOMDocument();$xml->loadXML(  $this->nusoap_client->call('get_user_info',$parameters))    ;// 以上是把返回的XML字符串装入DOM中,下面就可以直接索取值了。$user_id = $xml->getElementsByTagName('id')->item(0)->nodeValue;echo $user_id;die;return $result;}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值