我正在尝试获取具有不同类名的两个跨度的值并将其放入数组中
这是html
$html = '<div class="members">
<span class="records">Name: </span>
<span class="values">Marco</span>
</div>
<div class="members">
<span class="records">Mobile: </span>
<span class="values">+9431109890</span>
</div>
<div class="members">
<span class="records">Age: </span>
<span class="values">33</span>
</div>
<div class="members">
<span class="records">Sex: </span>
<span class="values">Male</span>
</div>'
至于现在我有这个代码
preg_match_all("/\<span class\=\"records\"\>(.*?)\<\/span\>/", $html, $records);
preg_match_all("/\<span class\=\"values\"\>(.*?)\<\/span\>/", $html, $values);
$valueresult = implode("\n", $records[1]);
$recordresult = implode("\n", $values[1]);
我不知道如何将其放入数组中,或者您是否有更好的 coeds 将其放入数组中。
结果必须是
array(
'Name' => 'Marco',
'Mobile' => '+000000000',
'Age' => '33',
'Sex' => 'Male,
)