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
?>
精彩评论