开发者

PHP - Cutting filenames

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜