I am trying to write some eBay descriptions in a csv file. I am using an input csv file with MPNs which I use to search the listings and retrieve the info there. However when I use preg_match
to find matches for descriptions, nothing is found. Here is my code:
$itemsUrl = readCSV(realpath(dirname(__FILE__)) . DS . 'JeepToysEbayIsr.csv');
$stream = fopen(realpath(dirname(__FILE__)) . DS . 'pssc_description.csv', 'w');
fputcsv($stream, array('MPN', 'Description'));
foreach ($itemsUrl as $itemNumber => $itemUrl) {
$item = array();
print_r($itemNumber . "\n");
$item['url'] = "http://www.ebay.co.uk/itm/".$itemUrl['MPN'];
//print_r($item);
$data = get_web_page($item['MPN'],"\n");
$come = true;
foreach ($data as $k => $row) {
// if (preg_match('/id="\'?vi-ilComp"\'?/',$row)) {
// $item['ktypes'] = 'yes';
// }
if (stripos($row, "<iframe") !== false) {
preg_match("/src=\"(.*?)\"/", $row, $matches);
if (isset($matches[1])) {
$desc = get_web_page($matches[1], "\n");
$desc = implode("\n", $desc);
$desc = preg_replace("/\r?\n|\r\/g/", "", $desc);
// print_r($desc);die();
$item['Description'] = $desc;
unset($desc);
}
}
}
// print_r($item);die();
// if (!isset($item['ktypes'])) {
// $item['ktypes'] = 'No';
// }
$msg['MPN'] = $itemUrl['MPN'];
if (isset($item['Description'])) {
$msg['Description'] = $item['Description'];
//print_r($desc);
}
foreach ($msg as $key => $value) {
fputcsv($stream, array($value), "\"");
}
}
fclose($stream);
print_r("\n" . 'Script finished working at ' . date('Y-m-d H-i-s') . " .\n");
Example data which I used:
MPN
FOR-15-001/30
FOR-15-002/30
FOR-15-002/40
FOR-15-003/30
FOR-15-003/40