您可能需要所有字段:
$in = '<a href="example.com/edit"> Edit Your Delivery Details </a>Pickup From: Washington, DC, USA<br>Deliver To: WDG Architecture, Connecticut Avenue Northwest, Washington, D.C., DC<br>Special Instruction: Yes, order fast<br>Person Name: sdf<br>Person Contact: dfsdf<br>Person Email: sdfsdasd@asd.asd<br>Pickup Day: Today<br>Pickup Time: ASAP<br><br>';
$lines = explode("<br>", $in);
$matches = array();
foreach ($lines as $line) {
if (strstr($line, ":")) {
$matches[] = preg_split("/\s*:\s*/", $line, 2);
}
}
print_r($matches);
给出:
Array
(
[0] => Array
(
[0] => Edit Your Delivery Details
Pickup From
[1] => Washington, DC, USA
)
[1] => Array
(
[0] => Deliver To
[1] => WDG Architecture, Connecticut Avenue Northwest, Washington, D.C., DC
)
[2] => Array
(
[0] => Special Instruction
[1] => Yes, order fast
)
[3] => Array
(
[0] => Person Name
[1] => sdf
)
[4] => Array
(
[0] => Person Contact
[1] => dfsdf
)
[5] => Array
(
[0] => Person Email
[1] => sdfsdasd@asd.asd
)
[6] => Array
(
[0] => Pickup Day
[1] => Today
)
[7] => Array
(
[0] => Pickup Time
[1] => ASAP
)
)
正如你所看到的,它还不是很完美,但它能让你到达那里。
使用 strpos 查找</a>
和修剪。如果你有更多这样的噪音,你也需要修剪它。
对投反对票的人:你能解释一下你的投反对票吗?我错过了什么?