I suggest use an HTML Parser instead. Use DOMDocument
+ DOMXpath
, no need to install they are built-in already. Example:
$ch = curl_init ("http://www.digionline.ir/Allprovince/CategoryProducts/cat=10301");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$page = curl_exec($ch);
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($page);
libxml_clear_errors();
$xpath = new DOMXpath($dom);
$data = array();
// get all table rows and rows which are not headers
$table_rows = $xpath->query('//table[@id="tbl-all-product-view"]/tr[@class!="rowH"]');
foreach($table_rows as $row => $tr) {
foreach($tr->childNodes as $td) {
$data[$row][] = preg_replace('~[\r\n]+~', '', trim($td->nodeValue));
}
$data[$row] = array_values(array_filter($data[$row]));
}
echo '<pre>';
print_r($data);
$data
should contain:
Array
(
[0] => Array
(
[0] => AMDA4-3400
[1] => 1,200,000
[2] => 1,200,000
)
[1] => Array
(
[0] => AMDSempron 145
[1] => 860,000
[2] => 910,000
)