Jump to content

get the current page name.


ted_chou12

Recommended Posts

okay, I finally got to here:
[code]
page=about
[/code]
but I want what is after the equal sign which is "about", how will I do that?
BTW I tried explode() and it doesnt work, nothing appears
which looks like this:
foreach($query as $v) {list($arg,$que) = explode("=",$v);}
can anyone give me any suggestions? thankyou
Ted.
Link to comment
Share on other sites

this is probably a round-a-bout way of getting it and will need some validating:

[code]
<?php

$url = "http://test.com/index.php";

$url_x = explode('.',$url);

$num = count($url_x);

$x = $num - 2;

$url_y = explode('/',$url_x[$x]);

$num = count($url_y);

$y = $num - 1;

$file = $url_y[$y];

?>
[/code]
Link to comment
Share on other sites

yeap get page does work, you made my life so simple now, but it doesnt seem to work for my function:
[code]
<?php
$test = $_GET['page'];
function menucurrent($que){if ($test == $que){echo "current";}}
?>
<ul>
<li id="<?php menucurrent("index")?>"><a href="index.php">Home</a></li>
<li id="<?php menucurrent("archives")?>"><a href="index.html">Archives</a></li>
<li id="<?php menucurrent("downloads")?>"><a href="index.html">Downloads</a></li>
<li id="<?php menucurrent("services")?>"><a href="include.php?page=services">Services</a></li>
<li id="<?php menucurrent("support")?>"><a href="include.php?page=support">Support</a></li>
<li id="<?php menucurrent("about")?>"><a href="include.php?page=about">About</a></li>
</ul>
[/code]
can anyone have a check please?
thanks
TED.
Link to comment
Share on other sites

The variable "$test" is not defined in the scope of the function. You can pass it in via the arguments, use the "global" statement in the function, or use $_GET['page'] in the function.

Here's the code that would pass it.

[code]<?php
$test = $_GET['page'];
function menucurrent($test,$que) {
  if ($test == $que) echo "current";
}
?>
<ul>
<li id="<?php menucurrent($test,"index")?>"><a href="index.php">Home</a></li>
<li id="<?php menucurrent($test,"archives")?>"><a href="index.html">Archives</a></li>
<li id="<?php menucurrent($test,"downloads")?>"><a href="index.html">Downloads</a></li>
<li id="<?php menucurrent($test,"services")?>"><a href="include.php?page=services">Services</a></li>
<li id="<?php menucurrent($test,"support")?>"><a href="include.php?page=support">Support</a></li>
<li id="<?php menucurrent($test,"about")?>"><a href="include.php?page=about">About</a></li>
</ul>
[/code]

The others are left as an exercise for the reader. :)

Ken
Link to comment
Share on other sites

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.