开发者

How do I get a part of a string in php? [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. 开发者_如何学运维 Closed 11 years ago.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜