arrays - PHP - How to get value of span with different class name -
i'm trying values of 2 span different class name , put array
this 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>'
as have code
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]);
i don't know how put in array or if have better coeds put in array.
result must be
array( 'name' => 'marco', 'mobile' => '+000000000', 'age' => '33', 'sex' => 'male, )
i'm not regex master, i've modified strip :
sign:
preg_match_all("/\<span class\=\"records\"\>(.*?):(.*?)\<\/span\>/", $html, $records); preg_match_all("/\<span class\=\"values\"\>(.*?)\<\/span\>/", $html, $values); $combined = array_combine($records[1], $values[1]); print_r($combined);
Comments
Post a Comment