Gets filename from current URL


/ Published in: PHP
Save to your folder(s)

Gets filename from current URL


Copy this code and paste it in your HTML
  1. // function to get current filename from a url made by sarfraz ahmed.
  2. function get_url_filename()
  3. {
  4. $filename = array_pop(explode("/",$_SERVER['REQUEST_URI']));
  5. $ext = substr($filename,strpos($filename,"."));
  6.  
  7. if (substr($ext,4))
  8. {
  9. if (substr($ext,4,1)=="?")
  10. {
  11. $ext = substr($ext,0,4);
  12. }
  13. else
  14. {
  15. $ext = substr($ext,0,5);
  16. }
  17. }
  18.  
  19. $filename = substr($filename,0,strpos($filename,"."));
  20.  
  21. return $filename . $ext;
  22. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.