如果使用使preg_split您可以通過分割你的數據:+和各部分進行
$str = <<<END
Subjects :: ADVERTISINGDOMAIN.COM - RSVP Open House Inquiry - Listing #839027
To :: [email protected]
ToName :: Matthew
From :: [email protected]
FromName :: XYZ Leads
RSVP for Open House
Listing #: 8390279
Open House Date: Sep 3, 2010
Name: John Doe
Phone: 5555555555
Email: [email protected]
Comments: Hi. I will be at the open house...looking forward to meeting you and viewing this property. Thanks. Jane
END;
$parts = explode("\n", $str);
foreach($parts as $part) {
// split by :+ and unlimited spaces
$data = preg_split('~[:]+\s*~', trim($part), null, PREG_SPLIT_NO_EMPTY);
if (count($data)) {
$final_data[] = $data;
}
}
print_r($final_data);
結果...
Array
(
[0] => Array
(
[0] => Subjects
[1] => ADVERTISINGDOMAIN.COM - RSVP Open House Inquiry - Listing #839027
)
[1] => Array
(
[0] => To
[1] => [email protected]
)
[2] => Array
(
[0] => ToName
[1] => Matthew
)
...
現在,如果您遍歷數組必須分開每個數組的位置0的「變量名」和位置1的變量數據。如果他們不直接與表字段對齊,則可以創建一個將表單字段映射到表字段的數組。
馬修 - 你能澄清一下你在找什麼嗎? – Rudu 2010-09-16 19:09:38
你有沒有使用正則表達式? – 2010-09-16 19:12:55