Php code to extract filename from urls.

This code will be useful to extract the names of the files from url

For E.g http://unicode.org/charts/PDF/U0B80.pdf

//Url to extract
$url='http://unicode.org/charts/PDF/U0B80.pdf';

//Code
$file1=preg_match("#(.*)\/(.*)(.pdf||.doc)#",$url,$file2);
$filename1=$file2[2];

//Outputs U0B80.pdf
echo $filename1;

This would output U0B80.pdf

This entry was posted on Sunday, October 25th, 2009 at 12:50 am and is filed under Php. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Post a Comment