lundi 30 mars 2015

Create array from string using php

I have a string like below



Final-Recipient: rfc822;test@example.com
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;test@example.com',
'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);

Aucun commentaire:

Enregistrer un commentaire