Page 1 of 1

PHP wildcard

Posted: Thu Dec 07, 2006 5:13 pm
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]

Posted: Thu Dec 07, 2006 5:21 pm
by RobertGonzalez
Regular Expressions. preg_match() I think would work.

Posted: Thu Dec 07, 2006 5:28 pm
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...";
}
//...

THANK

Posted: Thu Dec 07, 2006 5:43 pm
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 ;-)

Posted: Thu Dec 07, 2006 5:53 pm
by feyd
If you don't care what's after "admin" you could user strpos() for a bit faster performance.