I have three possible HTTP Post returns that I’m trying to get an Array out of with PHP 5.1.6.
I’m not exactly sure on the terminology of this (sorry).
<?PHP
// Values the $var could be:
$var = "<STATUS>SUCCESS</STATUS><BR><TIME>Mon Oct 17 20:44:41 PDT 2011</TIME>";
// OR
$var = "<STATUS>REJECTED</STATUS>";
// OR
$var = "<STATUS>ERROR</STATUS></BR><VALIDATION MESSAGE>200-Service and Zipcode is required.</VALIDATION MESSAGE> ";
// Output I'd like to see:
$array = Array (
['STATUS'] => 'SUCCESS',
['TIME'] => 'Mon Oct 17 20:44:41 PDT 2011',
['VALIDATION MESSAGE'] => ''
);
// OR
$array = Array (
['STATUS'] => 'REJECTED',
['TIME'] => '',
['VALIDATION MESSAGE'] => ''
);
//OR
$array = Array (
['STATUS'] => 'ERROR',
['TIME'] => '',
['VALIDATION MESSAGE'] => '200-Service and Zipcode is required.'
);
//Another way to look at the desired output array would be:
/*
Array
(
[STATUS] => SUCCESS
[TIME] => Mon Oct 17 20:44:41 PDT 2011
[VALIDATION MESSAGE] =>
)
// OR
Array
(
[STATUS] => REJECTED
[TIME] =>
[VALIDATION MESSAGE] =>
)
// OR
Array
(
[STATUS] => ERROR
[TIME] => Mon Oct 17 20:44:41 PDT 2011
[VALIDATION MESSAGE] =>
)
*/
?>
Maybe a preg_match or ??? (preg_match is still a little baffling to me at this point)
I’ve been spinning my wheels thus far.
Thanks!
As you have a simple pattern, you can just parse it with
sscanfand assign it to the array keys:$array:Demo / Demo (old)