PHP Simple DOM Parser extract single value from two url -
i use dom parser grab text 2 html documents same li
class , retrieved double value.
<?php include_once('simple_html_dom.php'); $links = array ( "model_one" => "car.html", "model_two" => "car/edition.html" ); foreach ($links $key=>$link) { $html = file_get_html($link); $ret[] = $html->find('ul li[class=dotcar]',0)->plaintext; $pattern = '/.\d+(?:\.\d{2})?((?<=[0-9])(?= usd))/'; preg_match_all($pattern, $ret[0], $result); $price = array(); foreach($result[0] $k=>$v) { $price[] = $v; echo $price[0]; } } // $price[0]= 10.55 11 ?>
how can associate model_key
$links
array value $price
obtain result:
model_one 10.55 model_two 11.00
in way can retrieve single value insert in mysql table.
perhaps this:
foreach($result $k=>$v) { //$v price (10.55 etc.) foreach($links $kk=>$vv) { //$vv link (model_one etc.) $priceandlinks[$vv] = $v; } }
this might give idea of logic needed.
Comments
Post a Comment