【发布时间】:2017-04-24 01:10:42
【问题描述】:
我有一个数组,我知道它的值是来自某个地方的 JPG
我需要转到返回到该数组的每个值并 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??!
第一段代码适用于所有值,替换工作正常。
第二段代码是我的问题,它返回旧的未修改图像的值,我没有
我需要在写入图像之前对其进行修改 '$product->imageUrl & $product->subImageUrl'
【问题讨论】:
标签: php arrays preg-replace