I need your help with a RegEx in PHP
I have something like: vacation.jpg and I am looking for a RegEx which extracts me only the 'vacation' of the filename. Can someone help me?
I need your help with a RegEx in PHP
I have something like: vacation.jpg and I am looking for a RegEx which extracts me only the 'vacation' of the filename. Can someone help me?
You can use pathinfo instead of Regex.
$file = 'vacation.jpg';
$path_parts = pathinfo($file);
$filename = $path_parts['filename'];
echo $filename;
You don't need regex for this.
Approach 1:
$str = 'vacation.jpg';
$parts = explode('.', basename($str));
if (count($parts) > 1) array_pop($parts);
$filename = implode('.', $parts);
Approach 2 (better, use pathinfo()):
$str = 'vacation.jpg';
$filename = pathinfo($str, PATHINFO_FILENAME);