Explode from last parameter

I need to explode a filename between its last dot “.” , and have in one hand the name and in the other the extension. It would be done easily with


$arr_name= explode(".",$filename);

but… when the filename has a dot in its name, eg: “Doc. for Sitepoint.xls” it would cut me the filename in the wrong position. Any clues?

Hi AnthonySterling
Thanx for the better solution. I will be using this from now.

Take a look at [fphp]pathinfo[/fphp]. :wink:


<?php
error_reporting(-1);
ini_set('display_errors', true);

print_r(
  pathinfo('/path/to/my/document.from.finance.xml')
);

/*
  Array
  (
     [dirname] => /path/to/my
     [basename] => document.from.finance.xml
     [extension] => xml
     [filename] => document.from.finance
  )
*/
?>

hi This might help you.


$original="Doc. for Sitepoint.xls";
$arr_name= explode(".",$original);
$extension=$arr_name[count($arr_name)-1];
$filename="";
for($i=0;$i<count($arr_name)-1;$i++){
	$filename.=$delim.$arr_name[$i];
	$delim=".";
}
echo "Original Name: ".$original."<br />filename: ".$filename."<br />Extension: ".$extension;