1

I need to remove all text from url before last slash /

$url = https://example.com/aaa/bbbb/ccc/ttt/img.jpg 

The output must be img.jpg

Also note /aaa/bbb/ccc/ttt in not the same

  • must use regular expresion
  • must be php 7 compatible
5

Simplest solution should be $file = basename($url);

See: http://php.net/manual/en/function.basename.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.