shortysbest Posted April 2, 2010 Share Posted April 2, 2010 What I want to do is echo the current page url. but not the whole url just one part of it. The URL im trying to execute is: /sw.php?page=home I only know how to echo out the whole /sw.php?page=home, and just sw.php. But I want to echo out only "home" nothing else. I would like the code to be able to be placed on the template page and get the page url for the one you are on. And if there would be anyway to automatically capitalize the first letter in the word that would be great too. Quote Link to comment https://forums.phpfreaks.com/topic/197358-how-to-echo-current-page-url/ Share on other sites More sharing options...
KevinM1 Posted April 2, 2010 Share Posted April 2, 2010 Try: echo $_GET['page']; Quote Link to comment https://forums.phpfreaks.com/topic/197358-how-to-echo-current-page-url/#findComment-1035905 Share on other sites More sharing options...
GetPutDelete Posted April 2, 2010 Share Posted April 2, 2010 Ok, you're trying to get the contents of a variable (URL variables are listed after the question mark (?) and separated by (&). To echo these variables use <?php echo $_GET['page']; ?> An example using multiple variables in the URL... (URL is http://example.com/?my_name=bob&fav_color=blue&age=23) <?php echo 'My name is ' . $_GET['my_name'] . ' my favourite color is ' . $_GET['fav_color'] . ' and I am ' . $_GET['age'] . ' years old.'; ?> I hope that helps. Quote Link to comment https://forums.phpfreaks.com/topic/197358-how-to-echo-current-page-url/#findComment-1035906 Share on other sites More sharing options...
shortysbest Posted April 2, 2010 Author Share Posted April 2, 2010 Try: echo $_GET['page']; Night, that did just what i wanted.. i could have sworn i tried that before though. But thanks. =P Quote Link to comment https://forums.phpfreaks.com/topic/197358-how-to-echo-current-page-url/#findComment-1035907 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.