PHP - 在 PHP 中将 XML 转换为数组 - 在 php 中解析一个 soap xml 并将其存储在数据库中

PHP - converting XML to array in PHP - parsing a soap xml in php and storing it in database(PHP - 在 PHP 中将 XML 转换为数组 - 在 php 中解析一个 soap xml 并将其存储在数据库中)
本文介绍了PHP - 在 PHP 中将 XML 转换为数组 - 在 php 中解析一个 soap xml 并将其存储在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我想转换一个soap xml 响应并将其存储在数据库中.这是我拥有的 XML.

I want to convert a soap xml response and store it in a database. Here is the XML that I have.

<ENV:Envelope xmlns:ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://example.com/soap/example">
   <ENV:Body>
      <ns1:GetCentresResponse>
         <ExampleCentre>
            <ns1:Cent>
               <ID>200</ID>
               <Name>example2</Name>
               <Code>ex2</Code>
               <Email>example2@example2.com</Email>
               <Address1>example2, example2 </Address1>
               <Address2>example2, example2 </Address2>
               <City>example2</City>
               <PostCode>111111</PostCode>
               <Telephone>1111111111</Telephone>
               <Location>11.11,-11.11</Location>
               <URL>/example2/exam2/ex2</URL>
            </ns1:Cent>
         </ExampleCentre>
      </ns1:GetCentresResponse>
   </ENV:Body>
</ENV:Envelope>

我从服务器得到这个soap响应.我想将其转换为数组并将其存储在数据库中.我该怎么办?我知道答案可能很简单,但是嘿,我是新手 :D

I get this soap response from the server. I want to convert this to a array and store it in database. What should I do? I know the answer might be pretty straight forward, but hey, am a newbie :D

非常感谢我得到的任何帮助.

Would really appreciate any help I get.

谢谢你的期待.

问候

推荐答案

最好的解决方案是使用 PHP 的 SoapClient 类进行调用,该类将返回一个对象,然后将该对象转换为数组,如下所示:

The best solution would be to use PHP's SoapClient class to do the call which will return you an object and then converting this object to an array, like so:

<?php
$client = new SoapClient("http://localhost/code/soap.wsdl");

// Soap call with HelloWorld() method
$something =  $client->HelloWorld(array('option1' => 'attribute1'));

// Convert object to array
$array = (array)$something;

?>

然后您可以将其存储在数据库中.

Which you can then store in the database.

这篇关于PHP - 在 PHP 中将 XML 转换为数组 - 在 php 中解析一个 soap xml 并将其存储在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Subtract time in PHP(在 PHP 中减去时间)
Limit execution time of an function or command PHP(限制函数或命令 PHP 的执行时间)
How to sum N number of time (HH:MM Format)?(如何求和 N 次(HH:MM 格式)?)
How to get current time in milliseconds in PHP?(如何在 PHP 中以毫秒为单位获取当前时间?)
How to check if time is between two times in PHP(如何检查时间是否在 PHP 中的两次之间)
Convert number of minutes into hours amp; minutes using PHP(将分钟数转换为小时数分钟使用 PHP)