Remove resolution string from image url in PHP

前端 未结 4 573
误落风尘
误落风尘 2021-01-23 03:58

I have following image url:

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

Here url con

相关标签:
4条回答
  • 2021-01-23 04:30

    You can try

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

    Replace with:$1$2

    0 讨论(0)
  • 2021-01-23 04:32
    $str=preg_replace("/^(.+)-\d+?x\d+?(\.\w+)$/i","$1$2",$str);
    
    0 讨论(0)
  • 2021-01-23 04:40

    preg_replace

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

    There are a lot of ways.

    0 讨论(0)
  • 2021-01-23 04:54

    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);
    
    0 讨论(0)
提交回复
热议问题