我这里有一个PHP代码
$productDetails['country'][0]['image']
输出是:
http://localhost/wine-works.co.uk-tester/wp-content/uploads/2013/09/canada-wine_shop.jpg
如何将文件名更改为:
http://localhost/wine-works.co.uk-tester/wp-content/uploads/2013/09/canada-wine_shop-25x17.jpg
答案 0 :(得分:0)
$str= 'http://localhost/wine-works.co.uk-tester/wp-content/uploads/2013/09/canada-wine_shop.jpg';
$suffix = '-25x17';
$name = substr($str,strrpos($str,'/')+1);
$leftString = substr($str,0,strrpos($str,'/')+1);
$extension = substr($name,strrpos($name,'.'));
$nameNoExtension = substr($name,0,strrpos($name,'.'));
$string = $nameNoExtension.$suffix.$extension;
echo $leftString.$string;
//http://localhost/wine-works.co.uk-tester/wp-content/uploads/2013/09/canada-wine_shop-25x17.jpg
答案 1 :(得分:0)
$d = pathinfo($productDetails['country'][0]['image']);
echo $new_name = $d['dirname'].'/'.$d['filename'].'-25x17.'.$d['extension'];