2017-04-24 25 views
0

我有一個數組,我知道,它的價值將是JPG格式從什麼地方與其他preg_replaced值

我需要去每個值返回到陣列和一些preg_replace函數替換字符數組值

然後設置返回值的數值爲其他值

這裏的代碼,並在這裏就是我試圖

//first piece of code 
$data['images'] = array(); 
     foreach ($single['PictureURL'] as $ispec) { 

      $data['images'][] = $ispec; 
      $ispec = preg_replace('/\$_[0-9]+.JPG\b/i', '$_10.JPG', $ispec); 
      $file = 'C:\wamp64\www\mz\images1.txt'; 
      file_put_contents ($file, $ispec, FILE_APPEND); 
//images1.txt shows all images returned fine with modified strings 
      } 

//second piece of code 
      $product->imageUrl = $data['images'][0]; 
      unset($data['images'][0]); 
      $product->subImageUrl = $data['images']; 
       $file = 'C:\wamp64\www\mz\images3.txt'; 
      file_put_contents ($file, $data['images'], FILE_APPEND); 
//images3.txt shows all the images returned but without being modified?? WHY??! 

第一塊的C Ode正在研究所有的價值,並且替換工作得很好。

第二塊代碼是我的問題,它返回舊的沒有修改圖像的價值觀,我不

我需要修改的圖像被寫入 之前「$產品 - > imageUrl & $ product-> subImageUrl'

回答

1

問題很簡單。在您已將 存儲在$data['images']之後,您正在修改您的數據。爲了解決這個問題,只需移動這條線 的preg_replace後:

foreach ($single['PictureURL'] as $ispec) { 
    $ispec = preg_replace('/\$_[0-9]+.JPG\b/i', '$_10.JPG', $ispec); 
    $data['images'][] = $ispec; 
    $file = 'C:\wamp64\www\mz\images1.txt'; 
    file_put_contents ($file, $ispec, FILE_APPEND); 
} 
+0

感謝隊友,是在邊緣開始打破東西:d –