使用php从字符串创建数组

使用php从字符串创建数组,php,string,Php,String,我有一根像下面这样的线 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'=>'fai

我有一根像下面这样的线

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);

展示您的尝试。否则,我们认为你没有,只是想让我们为你做你的工作。@johncode我将很快发布,请wait@JohnConde我更新了我的问题提示:你为什么要爆炸当它显然不是输入数据中的分隔符时?显示您已尝试的内容。否则,我们认为你没有,只是想让我们为你做你的工作。@johncode我将很快发布,请wait@JohnConde我更新了我的问题提示:你为什么要爆炸当输入数据中的分隔符显然不是分隔符时?我建议您将行拆分为
后跟空格,而不仅仅是
。否则您应该修剪
$t[1]
。我建议您将行拆分为
后跟空格,而不仅仅是
。否则您应该修剪
$t[1]
<?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);