Jump to content

how to echo current page url


shortysbest

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/197358-how-to-echo-current-page-url/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.