Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.