我有一个字符串,如下
Final-Recipient: rfc822;test@example.com
Action: failed
Status: 5.1.1
Diagnostic-Code: smtp;550 5.1.1 RESOLVER.ADR.RecipNotFound; not found
我需要将每个值作为一个类似的关联数组
array('Final-Recipient'=>'rfc822;test@example.com',
'Action'=>'failed',
'Status'=>'5.1.1',....)
我试过使用爆炸函数,但并没有给出预期的结果。
$result = array();
$temp = explode(';',$message);
foreach($temp as $value)
{
$temp2 = explode(':',$value);
$result[$temp[0]] = $result[$temp[1]];
}
print_r($result);
<?php
$str = 'Final-Recipient: rfc822;test@example.com
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);