Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
216 views
in Technique[技术] by (71.8m points)

PHP - Getting Current URL

This seems like a common questions but none of them seem to be what i'm looking for. If there is a website:

www.example.com/test.php

I want to pull the test.php and if it's something like:

www.example.com/folder/folder1/test.php

I want again to just pull test.php but everything seems to pull the exact path instead of just the page. Any suggestions?

question from:https://stackoverflow.com/questions/6475221/php-getting-current-url

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
$query = $_SERVER['PHP_SELF'];
$path = pathinfo( $query );
$what_you_want = $path['basename'];

Voila.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...