How to extract only part of string in PHP?
问题 I have a following string and I want to extract image123.jpg. ..here_can_be_any_length "and_here_any_length/image123.jpg" and_here_also_any_length image123 can be any length (newimage123456 etc) and with extension of jpg, jpeg, gif or png. I assume I need to use preg_match, but I am not really sure and like to know how to code it or if there are any other ways or function I can use. 回答1: You can use: if(preg_match('#".*?\/(.*?)"#',$str,$matches)) { $filename = $matches[1]; } Alternatively you