开发者

PHP - Cutting filenames

开发者 https://www.devze.com 2023-02-17 13:37 出处:网络
I was wondering if someone could help me. I have filenames being outputted by my database in the following type of format

I was wondering if someone could help me.

I have filenames being outputted by my database in the following type of format

filename-144x96.jpg

filename-144x180.jpg

file-name-144x180.jpg

etc etc etc

Is there a way that i can ditch everything including and after the last - ??

So that after it processed, the filenames would be

filename.jpg

filename.jpg

file-name.jpg

Im having some trouble trying to figure 开发者_开发知识库this one out.

Cheers,


<?php

$filename = "file-name-1440x80.jpg";
 echo preg_replace("/-\d+x\d+/i","", $filename);
// prints file-name.jpg

?>
0

精彩评论

暂无评论...
验证码 换一张
取 消