[php] Best way of finding current page?

Soldato
Joined
18 Oct 2002
Posts
9,044
Location
London
What's the best way of getting id="current" into the <li> for the page the user is currently on? It's only for a tiny site, example:

Code:
<ul>
	<li id="current"><a href="/index.php">Home</a></li>
	<li><a href="/managers.php">Managers</a></li>
	<li><a href="/suppliers.php">Suppliers</a></li>
	<li><a href="/employees.php">Employees</a></li>
	<li><a href="/customers.php">Customers</a></li>
	<li><a href="/stores.php">Stores</a></li>
	<li><a href="/films.php">Films</a></li>
	<li><a href="/genres.php">Genres</a></li>
</ul>


I was thinking

Code:
  if ($scriptname == "/managers.php") {
    <li id="current"><a href="managers.php">Managers</a></li>
  } else {
    <li><a href="/managers.php">Managers</a></li>
  }

But this seems like a lot of lines, and doesn't look very nice.
There must be a better way??? :o
 
Ahhh many thanks, used your 2nd example, very good :)

Never seen this before, although I'm no expert php coder anyway..
Code:
($scriptname == "/managers.php") ? ' id="current"' : '';

Cheers!
 
Back
Top Bottom