How do you use PHP to determine page names?

My question while it sounds basic is more complex. I am trying to get php to determine what to do with a function by looking at the pagename. If the page name has a certain word in it I want the function specific to that word to run.
//The URL would look something like this http://www.something.com/index.php?pagname=people_edit
 
//If I had to guess on how to do this I would do something like this.
$pagename = $_REQUEST['pagename'];
 
if($pagename == people_*){ // This is where I am having the problem. I want this to pick up people_add, people_edit, people_delete, etc.
  $do_this = "Something to do";
}
 
if($pagename == animal_*){ // I want this to pick up animal_add, animal_edit, animal_delete, etc.
  $do_this = "Something Different to do";
}

Open in new window

LVL 1
NEComputerAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SreejithGCommented:
You can get the page name from $_SERVER["REQUEST_URI"]
0
SreejithGCommented:
sorry, $_SERVER["SCRIPT_NAME"] gives the page name
0
NEComputerAuthor Commented:
actually, I am not trying to get the URI like "index.php" I use the $_SERVER['REQUEST_URI"] already for other purposes. I guess to rephrase my question I am trying to get php to use a wildcard to route variables.  people_* goes to this function and animal_* goes to the other function and so on. People_* couldbe people_add, people_edit, people_delete, people_something.
0
CompTIA Network+

Prepare for the CompTIA Network+ exam by learning how to troubleshoot, configure, and manage both wired and wireless networks.

SreejithGCommented:
OK, now the question is clear. You need to use regular expressions. See the hel for the function preg_match() in php
0
cr4ck3rj4ckCommented:
I suggest you read up on regular expressions, they will help you a lot.

I've attached some code below that should help you:
if(preg_match('/.*people_.*/', $_SERVER["REQUEST_URI"])){
  $do_this = "Something to do";
}
 
if(preg_match('/.*animal_.*/', $_SERVER["REQUEST_URI"])){
  $do_this = "Something Different to do";
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
NEComputerAuthor Commented:
Made some minor adjustments to your contribution cr4ck3rj4ack and your solution works great. Thanks to everyone that contributed.
0
NEComputerAuthor Commented:
Thank you for your feedback and example they helpded greatly. I actually just changed out your $_SERVER['REQUEST_URI'] and placed in the variable name and everything worked great. Again I appreciate the support.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.