tomdawson Posted June 29, 2009 Posted June 29, 2009 Hi guys, looking for some help with PHP. I'd like to display the current URL that you're looking at. At the moment I have: But this echoes the /index.php at the end. Any ideas how I could get rid of the /index.php, and just display the path that we're looking at. Thanks in advance Tom.
p858snake Posted June 29, 2009 Posted June 29, 2009 i don't know of any built in way to do it, but you could explode/strip (i forget what php calls it) the variable (parse_url) then so its cuts off anything after and including the "/" and then echo it.
DrPerceptron Posted June 30, 2009 Posted June 30, 2009 (edited) PHP: $_SERVER - Manual I'm sure one of those could help, I'm not sure what kind of URL you're trying to get though. It might be that you just need to drop the parse_url() function and just use $_SERVER['REQUEST_URI'] on its own. Edited June 30, 2009 by DrPerceptron
powdarrmonkey Posted June 30, 2009 Posted June 30, 2009 How much do you care about urls that end in some other file, like mypage.php? (better question: what exactly are you trying to achieve? there's probably an easier way)
tomdawson Posted June 30, 2009 Author Posted June 30, 2009 Unfortunately just the '$_SERVER['REQUEST_URI']' on its own still displays /index.php on the end, I just needed to hide the actual filename on the end (to make it nice and tidy!) If anyone's interested, I managed to bodge it together: $this_dir = $_SERVER['REQUEST_URI']; if (strpos($this_dir, basename($_SERVER['REQUEST_URI'])) !== false) $this_dir = reset(explode(basename($_SERVER['REQUEST_URI']), $this_dir)); echo $this_dir; ?> Now we get something like /directory1/otherthing/potato/ rather than /directory1/otherthing/potato/index.php Thanks for nudging me in the right direction
Guest leeneilson Posted June 30, 2009 Posted June 30, 2009 Glad you got it. If you wanted to see what was available from the $_SERVER superglobal then you could have printed out the array by doing this print_r($_SERVER);
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now