Jump to content

using preg_match


Vidya_tr

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.