PHP Download images` links from ebay listings to csv file

I am trying to download some images urls in a csv file. I am using the MPNs from an input csv file. I open each listing and search for image link, my array of links $itemInfo is empty. Here is my code:

$fRead = fopen("JeepToysEbayIsr.csv", "r");
while ($line = fgetcsv($fRead)) {
$ids[] = $line[0];
// print_r($ids);die();
$fp = fopen("AllImages.csv", "w");
fputcsv($fp, array("ebayId", "variationName", "images"));

foreach ($ids as $key => $id) {
// $id = '390573574298';
$url = ''.$id;
$data = get_web_page($url);

if(preg_match("/id=\"vi_main_img_fs\"(.*?)gspr flm-btn nxt/s", $data, $imageDiv)){
 preg_match_all("/<img(.*?)\/>/", $imageDiv[1], $imageTags);

$itemInfo = array();
$itemInfo['id'] = $id;
if (isset($imageTags[1])) {

foreach ($imageTags[1] as $img) {
    preg_match("/src=\"(.*?)\"/", $img, $url);
    $itemInfo[] = str_replace("l64", "l1600", $url[1]);
  if (preg_match("/id=\"mainImgHldr\"(.*?)<\/div/s", $data, $main) !== false) {
      if ($main) {
    preg_match("/icImg.*src=\"(.*?)\"/", $main[1], $matches);
    $itemInfo[] = $matches[1];
fputcsv($fp, $itemInfo);


I think in the match section something is not right so I am wondering what has to be changed?

Why do you want to change something? But anyway i don’t see how somebody should do something without a sample input of your CSV.

Here is what I use: HON-15-031/30,HYU-15-025/40- with these I open the url and search there for an image. Then I want to get the image link and put it in a csv file.

But that doesn’t look like a valid ID, i get an error when appending it to the URL and opening it in a browser.

It is actually an MPN and with it I open each listing and search for info.

Still does not give anything product related.

This is because my search pattern was wrong, I changed it and now the link is opened

Sponsor our Newsletter | Privacy Policy | Terms of Service