PHP wildcard

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
orbstra
Forum Commoner
Posts: 30
Joined: Thu Dec 07, 2006 5:07 pm

PHP wildcard

Post by orbstra »

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


OK this is a little confusing but bear with me:

Let me show the code then explain:

Code: Select all

$url = $_GET['l'];
		if($url =='admin' or $url=='admin/*')
			{
				echo '<div id="sidebar">';
				guav_admin_sidebar();
				echo '</div>';
			}
in this I want the * to be anything. This script takes teh URL's variable (L) and decides weather to echo the admin sidebar. I want the following to be acceptable for showing the Admin sidebar:

?l=admin
?l=admin/errorlogs
?l=admin/user


although I do not want to list these manually so I want

Code: Select all

if($url == 'admin' or $url == 'admin/ANYTHING')
to work. Thanks!


Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Regular Expressions. preg_match() I think would work.
User avatar
ok
Forum Contributor
Posts: 393
Joined: Wed May 31, 2006 9:20 am
Location: The Holy Land

Post by ok »

First of all, add [ p h p ] and [ / p h p ] tags around each code you post!

Secondly, I don't think that it is very wise to print admin menu only by the input from the GET (url).

But...

This one requires the use of regex:

Code: Select all

//...
if(preg_match("/admin(.*)/", $url))
{
 echo "Admin control panel...";
}
//...
orbstra
Forum Commoner
Posts: 30
Joined: Thu Dec 07, 2006 5:07 pm

THANK

Post by orbstra »

thanks fellas that just SAVED ME!

the code I posted was a dumbed-down version of the real thing. All the actual concent of the menu is only accessed by authentification... dont worry I am not that dum ;-)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you don't care what's after "admin" you could user strpos() for a bit faster performance.
Post Reply