I want to parse the string to a dataset through regex matching in PHP. Here is my code:
$string = "?\t\t\t\t\t\t?\t\t\t\t\t\t\t\t\t\t\t\t<?xml version=\"1.0\" encoding=\"UTF-8\"?><documents><Resp><gatewayId>g10060<\/gatewayId><accountId>310198232<\/accountId><orderNo>0970980541000510490500480<\/orderNo><tId><\/tId><tAmt>20<\/tAmt><result>1<\/result><respCode>21<\/respCode><signMD5>7ecd1eb9b870aaba3bfa45892095194e<\/signMD5><\/Resp><\/documents>";
preg_match_all('/<(.*?)>(.*?)<\\/(.*?)>/', $string, $arr);
echo json_encode($arr);
However it only returns me [[],[],[],[]]
, as empty arrays. I've tried the regex expression on https://regex101.com/, and it shows me the correct result, but it is not working on my server.
What I want is:
[ "gatewayId" => "g10060",
"accountId" => "310198232",
"orderNo" => "0970980541000510490500480",
"tId" => "",
"tAmt" => "20",
"result" => "1",
"respCode" => "21",
"signMD5" => "7ecd1eb9b870aaba3bfa45892095194e" ]
How can I fix this?