php get filename from url code example

Example 1: php get url path name

parse_url( $_SERVER[ 'REQUEST_URI' ], PHP_URL_PATH );

Example 2: filename php

echo "1) ".basename("/etc/sudoers.d", ".d").PHP_EOL;//sudoers
echo "2) ".basename("/etc/sudoers.d").PHP_EOL;//sudoers.d
echo "3) ".basename("/etc/passwd").PHP_EOL;//passwd
echo "4) ".basename("/etc/").PHP_EOL;//etc
echo "5) ".basename(".").PHP_EOL;//.
echo "6) ".basename("/");//

Example 3: php get current url without filename

echo '//'.$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);

Tags:

Php Example