<?php function foo1($src) { $res = explode('?', $src)[0]; $res = explode('/', $res); $res = array_pop($res); $res = explode('-', $res); $res = array_pop($res); return $res; } function foo2($src) { preg_match('#([^-/\?]+)(?:\?.*|$)#', $src, $m); return $m ? $m[1] : ''; } function foo($src) { $res = basename(parse_url($src)['path']); $res = explode('-', $res); $res = array_pop($res); return $res; } echo foo('img1.webp'), PHP_EOL; echo foo('/upl/img/2jf-img1.webp?id=2335'), PHP_EOL; echo foo('/upl/img/img1.webp?id=2335'), PHP_EOL; echo foo('/upl/img/2jf-img1.webp'), PHP_EOL; echo foo('/a/b/c/d/e/f/g/h/i/img1.webp'), PHP_EOL;
You have javascript disabled. You will not be able to edit any code.