Help - Search - Members - Calendar
Full Version: Wildcard Operator
Weborum Webmaster Forum > Web Page Design > PHP
sjthomas
I'm trying to find out the last section of the current url of a page and then run an if statement on it. I want to find out if the url contains the admin folder. So basically I want it to look like this:

PHP

<?
$location
= $PHP_SELF;
$url = explode(".com/", $location, 2);
$url[1] = $endURL;
if (
$endURL &#33;= 'admin/*') {
    // do whatever
} else {
        
// do whatever else!
}
?>



Its the wildacrd bit I can't figure out. I've put admin/* in there just as a reference for myself, I know it can't be done that way but does anyone know how it can be done?

Cheers.
Willy Duitt
QUOTE(sjthomas @ Feb 7 2005, 07:39 AM)
I'm trying to find out the last section of the current url of a page and then run an if statement on it.  I want to find out if the url contains the admin folder.  So basically I want it to look like this:

PHP

<?
$location
= $PHP_SELF;
$url = explode(\".com/\", $location, 2);
$url[1] = $endURL;
if (
$endURL &#33;= 'admin/*') {
    // do whatever
} else {
        // do whatever else!
}
?>



Its the wildacrd bit I can't figure out.  I've put admin/* in there just as a reference for myself, I know it can't be done that way but does anyone know how it can be done?

Cheers.
[right][snapback]22782[/snapback][/right]


I would think something like this should work:

PHP
if (preg_match("/admin\//", $location))


.....willy
sjthomas
Cheers Willy that works a treat. I really should learn regexp at some point....
Willy Duitt
QUOTE(sjthomas @ Feb 7 2005, 10:00 AM)
Cheers Willy that works a treat.  I really should learn regexp at some point....
[right][snapback]22797[/snapback][/right]


You might want to use the case insensitive flag if there is any possibility that the admin folder name may be either upper or lower case...

if (preg_match("/admin\//,i", $location))

.....Willy
Waleed
is there anything you don't know, Willy?
Willy Duitt
QUOTE(Waleed Zuberi @ Feb 7 2005, 10:40 AM)
is there anything you don't know, Willy?
[right][snapback]22800[/snapback][/right]


I don't know how to stay out of trouble... w00t.gif

I have:
  • Had my pilots license suspended for flying under a suspension bridge...
  • Was pulled over while naked with an open bottle of Jack Daniels, marijuana, loaded weapons, and a naked woman whom started crying...
  • Blown up more things than I can count, some intentionally, some not...
  • Dove head first off a 150 foot cliff and knocked myself out, nearly drowning...
  • Made a bazooka out of PVC pipe and shot a model class aaa rocket out of it which went over a mile (surprised the hell outta me) and landed in a residential area which brought the ATF out investigating...

Should I go on... Actually, I'm one dumb sum-a-biatch....
There was a time when I was young that parents would not let thier children play with me... I thought I outgrew that but now, wives won't let their husbands play with me!! whistle.gif

.....Willy

sjthomas
QUOTE(Willy Duitt @ Feb 7 2005, 06:01 PM)
There was a time when I was young that parents would not let thier children play with me... I thought I outgrew that but now, wives won't let their husbands play with me!!  whistle.gif

.....Willy
[right][snapback]22809[/snapback][/right]


I guess the only problem there is husbands letting their wives play with you!
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2008 Invision Power Services, Inc.