Quantcast
Channel: Convert xml string to json in php - Stack Overflow
Viewing all articles
Browse latest Browse all 2

Convert xml string to json in php

$
0
0

I have the fokllowing xml string that i'd like to convert to a json string.

Here is the xml in a variable:

$output = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:req="http://api-v1.gen.mm.vodafone.com/mminterface/request"><soapenv:Header/><soapenv:Body><req:ResponseMsg><![CDATA[<?xml version="1.0" encoding="UTF-8"?><response xmlns="http://api-v1.gen.mm.vodafone.com/mminterface/response"><ResponseCode>100000014</ResponseCode><ResponseDesc>Missing mandatory parameter:OriginatorConversationId</ResponseDesc><ConversationID></ConversationID><OriginatorConversationID></OriginatorConversationID><ServiceStatus>0</ServiceStatus></response>]]></req:ResponseMsg></soapenv:Body></soapenv:Envelope>';

Then I'm using this regex to convert it but it returns blank.

$pattern = "(<Response(.+)>[\s\S]*?<\/Response>)";preg_match_all($pattern, $output, $matches);$xml = simplexml_load_string($matches[0][0]);echo json_encode($xml);

What am i missing?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images