How do I get a part of a string in php? [closed]
I have a function that returns a string "_" . $mime_type . ".jpg"
by default.
If the output string returns for example "_jpg.jpg"
I want to remove the "_"
and the last part ".jpg"
. Thus, returning the string "jpg"
. What php function should I use?
$old_string = "_jpg.jpg";
preg_match('/_(.*)\./', $old_string, $matches);
if (!empty($matches)) $new_string = $matches[1];
I think preg_match() is the way to go
精彩评论