2011-09-27 133 views
1

我有这组数据从一个textareaPHP爆炸帮助

P234324, 2011-03-23 12:34:37 \nP234434, 2011-03-23 13:34:36 \nP438794, 2011-03-23 14:34:36 \nP238924, 2011-03-23 15:34:36 \n 

我想它爆炸到这一点,但多的foreach是扔我。

$data['P234324'] = "2011-03-23 12:34:37" 
$data['P234434'] = "2011-03-23 13:34:36" 
$data['P438794'] = "2011-03-23 14:34:36" 
$data['P238924'] = "2011-03-23 15:34:36" 

回答

1

这将工作:

$old_data = ...; //your string 
$data = array(); 

$pairs = explode("\n", rtrim($old_data, "\n")); 
foreach($pairs as $pair) { 
    $components = explode(',', $pair); 
    $data[$components[0]] = trim($components[1]); 
} 

codepad example