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.
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]
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.
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

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.