WOOT! Who fancies playing "How many different ways can I solve this"?
(I know that soudns sarcastic but it's really not, I love trying to figure out different sollutions to a single problem)
substr:
$pos = strrpos($path, '.');
if($pos !== false) {
$result = substr($path, 0, $pos);
}
preg_match:
if(preg_match('/^(.*)\..*?$/', $path, $matches)) {
$result = $matches[1];
}
preg_replace:
$result = preg_replace('/\..*?$/', '', $path);
One thing I've noticed with my (and laserlight's second) sollutions are that if there is no dot in the filename but there is a dot earlier in the path, then the path will still be chopped, so...
substr:
$pos1 = strrpos($path, '.');
$pos2 = strrpos($path, DIRECTORY_SEPARATOR);
if($pos1 !== false && ($pos2 === false || $pos2 < $pos1)) {
$result = substr($path, 0, $pos1);
}
preg_match:
if(preg_match('#^(.*)\.[^'.DIRECTORY_SEPERATOR.']*$#', $path, $matches)) {
$result = $mathes[1];
}
preg_replace:
$result = preg_replace('#\.[^'.DIRECTORY_SEPERATOR.']*$#', '', $path);
So far, I think I like laserlight's first sollution best.