Reputation: 7768
I have a string like below
Final-Recipient: rfc822;[email protected]
Action: failed
Status: 5.1.1
Diagnostic-Code: smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found
I need to get each value as an associative array like
array('Final-Recipient'=>'rfc822;[email protected]',
'Action'=>'failed',
'Status'=>'5.1.1',....)
I was try with explode function,But it don't give result expected.
$result = array();
$temp = explode(';',$message);
foreach($temp as $value)
{
$temp2 = explode(':',$value);
$result[$temp[0]] = $result[$temp[1]];
}
print_r($result);
Upvotes: 0
Views: 84
Reputation: 7785
<?php
$str = 'Final-Recipient: rfc822;[email protected]
Action: failed
Status: 5.1.1
Diagnostic-Code: smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found';
$res = array ();
foreach (explode (PHP_EOL, $str) as $e) {
$t = explode (':', $e);
$res[trim($t[0])] = trim($t[1]);
}
var_dump($res);
Upvotes: 4