从当前页面抓取子文件夹和文件名

I couldn't find another questions with the exact specs I'm needing here. So I'm posting this.

I need to use php to grab the url of the current page. http//example.com/mysubfolder/filename.php

I need it to print out: mysubfolder/filename

And if the filename.php has a get formula ?action=move or ?id=798 I would simply need to strip those portions off. The farthest I've seen in manuals will help to subtract only a specific portion of the .?action=doesntchangeathing

Most of what I have seen includes just the filename or a complete list of subfolders, not just one and would be using an absolute path rather than the url.

Anyone have any ideas?

You can use $_SERVER['PHP_SELF'] and cut filename extension and leading slash, so resulted expression may look something like this:

$path = implode('/', [trim(dirname($_SERVER['PHP_SELF']), '/'), pathinfo($_SERVER['PHP_SELF'], PATHINFO_FILENAME)]);