你好,我有这个代码:
foreach ($image as $snimka){
$url = $snimka->src;
$ch = curl_init($snimka->src);
$fp = fopen('images/' . basename($url), 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
echo basename($url);
echo '<br />';
}
这段代码工作正常但在开始绘制图片之前转移部分src,这就是我想到的以下src partnersite.com/363-cart_default/kecove-nora-zhylto-i-sinio.jpg我想改变购物车中的一个单词变大,然后开始下载图片怎么办请帮助
我解决了我的问题,这是解决方案:
foreach ($image as $snimka){
$url = $snimka->src;
$replace = preg_replace('~cart~','large',$url);
$ch = curl_init($replace);
$fp = fopen('images/' . basename($url), 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
curl_close($ch);
fclose($fp);
echo basename($url);
echo '<br />';
}
答案 0 :(得分:0)
根据您当前的问题,这里举例说明_default /如何变成_large /.
echo preg_replace ( '|_default\/|', '_large/' , 'partnersite.com/363-cart_default/kecove-nora-zhylto-i-sinio.jpg');