项目中应用到了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;}
php 生成xml字符串,PHP解析返回的XML字符串
最新推荐文章于 2022-08-27 11:14:26 发布