I'm wanting to use a preg_replace only to replace
"http://domain.com/dateiIe6EHOnzyl/_DSC7290.jpg.htm"
to
"http://domain.com/dateiIe6EHOnzyl.htm"
p/s: I need using only preg_replace
$link = preg_replace('~/[^/]*(\.html?)$~', '$1', $link);
Try without preg_replace(), but with explode() and str_replace(), like in this example:
$str = 'http://domain.com/dateiIe6EHOnzyl/_DSC7290.jpg.htm';
$lastpart = end(explode('/', $str));
$str2 = str_replace('/'.$lastpart, '.htm', $str);
echo $str2; // http://domain.com/dateiIe6EHOnzyl.htm
$str = 'http://domain.com/dateiIe6EHOnzyl/_DSC7290.jpg.htm';
$str = preg_replace('/(.+)\/.+\.(.+)/','$1.$2',$str);
print $str;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.