从PHP中的图像URL中删除分辨率字符串

从PHP中的图像URL中删除分辨率字符串

问题描述:

I have following image url:

http://www.example.org/wp-content/blogs.dir/29/files/2013/02/Personalized-Results-Asterisk-600x417.png

Here url containing by default resolution i.e. 600x417.png in it. I want to remove this resolution from this image url.

Final output of image url should be like this :

http://www.example.org/wp-content/blogs.dir/29/files/2013/02/Personalized-Results-Asterisk.png

How can I do this?

我有以下图片网址: p>

  http://  www.example.org/wp-content/blogs.dir/29/files/2013/02/Personalized-Results-Asterisk-600x417.png
nn

这是网址 默认包含分辨率,即 600x417.png code>。 我想从此图片网址中删除此分辨率。 p>

图片网址的最终输出应如下所示: p>

  http://  www.example.org/wp-content/blogs.dir/29/files/2013/02/Personalized-Results-Asterisk.png
nn

我该怎么办 这个? p> div>

Try this :

$string = 'http://www.example.org/wp-content/blogs.dir/29/files/2013/02/Personalized-Results-Asterisk-600x417.png';
$pattern = '/\-*(\d+)x(\d+)\.(.*)$/';
$replacement = '.$3';
echo preg_replace($pattern, $replacement, $string);

$str=preg_replace("/^(.+)-\d+?x\d+?(\.\w+)$/i","$1$2",$str);

preg_replace

$correct_url = preg_replace('`\-[0-9]*x[0-9]*(\.[^\.]*)$`','$1',$url);

There are a lot of ways.

You can try

Regex:^(.*?)-\d+x\d+\.([^/]+)$

Replace with:$1$2