我有这样的网址
URL = http://mysite1.com/some/path/to/file/{宽度}x{高度}/图像.jpg
我想从网址中取出{宽度}x{高度},这样我就可以
http://mysite1.com/some/path/to/file/image.jpg
我如何在 php 中使用正则表达式做到这一点谢谢
这个正则表达式应该这样做:
$url = 'http://mysite1.com/some/path/to/file/123x456/image.jpg';
$result = preg_replace('#/[0-9]+x[0-9]+#', '', $url);
echo $result;
搜索
^(http.*[//])(.*)[//](.*jpg)$
并替换为
'1'3
$url = 'http://mysite1.com/some/path/to/file/{width}x{height}/image.jpg';
echo str_replace("/{width}x{height}", "", $url);
输出:
http://mysite1.com/some/path/to/file/image.jpg