开发者

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

开发者 https://www.devze.com 2023-04-11 06:50 出处:网络
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 applic
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

精彩评论

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

关注公众号