Get Current Page URL Page Only

I am trying to get a page URL but without anything else,
if I do:

echo $_SERVER[‘PHP_SELF’];

I get something like
/my_app/index.php
/my_app/settings.php

Is there a way to get
index
settings

without the php and without the parent folder?

I dont want to manually edit this out because there may be an already made function I dont know about.

Not maybe a perfect solution, but still a solution:

$val = explode(".",$url);
echo $val[0]; //print index/settings with dir
echo $val[1];//print php/html etc

You can further minimize the $val[0] for your need.

I tried basename also, it appears safe to use…

echo str_replace(‘.php’, ‘’, basename($_SERVER[‘PHP_SELF’]));

You can just do


basename($_SERVER['PHP_SELF'],".php");

if all files are php…

Taking that one step more, you can do

$info = pathinfo($file);
$file_name =  basename($file,'.'.$info['extension']);

echo $file_name;

$path = pathinfo('/www/htdocs/index.html');
echo $path['filename']; // "index" since PHP 5.2.0

thanks guys,
i like that basename(phpself, .php) imma test it out today :slight_smile: