Vidya_tr Posted March 31, 2009 Share Posted March 31, 2009 I'm trying to use preg_match to split a file name into it's components. For example, if the filename is "sample.flv" I'd like "sample" to be set to $stem and "flv" set to $extension. I've tried using a preg_match function below, but doesn't seem to work as I expect. Can anyone fix it? <?php $name = $_FILES['user_file1']['name']; $name = strtolower($name); preg_match('/^(.*)(\..*)?$/', $name, $matches); $stem = $matches[1]; $extension = $matches[2]; ?> I am getting value of $stem as 'sample.flv' and nothing in $extension. Link to comment https://forums.phpfreaks.com/topic/151889-using-preg_match/ Share on other sites More sharing options...
vbnullchar Posted March 31, 2009 Share Posted March 31, 2009 try this http://php.net/pathinfo Link to comment https://forums.phpfreaks.com/topic/151889-using-preg_match/#findComment-797619 Share on other sites More sharing options...
Ayon Posted March 31, 2009 Share Posted March 31, 2009 what I've found as the easiest way for getting the extension of a file is using end(explode(".",filename.php)); Link to comment https://forums.phpfreaks.com/topic/151889-using-preg_match/#findComment-797650 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.