SunQuest
 
           General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old February 19th, 2003, 10:49 AM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
regex for path determination

I have a config file I use for public stuff as well as admin stuff

I need help constructing a regex that can find the word "admin" when I pass $_SERVER['SCRIPT_NAME'] to it.

So when I echo $_SERVER['SCRIPT_NAME'] now I get /pps/admin/mypages.php


I have never looked into regex's before, and there may be a better way of doing what I need to do. If you know of one, lemme know,..


TIA
__________________
-- Jason

Reply With Quote
  #2  
Old February 19th, 2003, 02:19 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Well, you don't need a regexp for it. You can do ->

PHP Code:
if ( stristr$_SERVER['SCRIPT_NAME'] ), 'admin' ) {
/* do something */
} else {
/* not in string */

__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #3  
Old February 19th, 2003, 02:24 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
This works:

PHP Code:
<?php

  $isAdminPage 
false;
  
  
$thePath "/pps/not_an_admin_page.php";
  
//$thePath = "/pps/fakeadmin.php";
  //$thePath = "/pps/admin/mypage.php";
  
  
$aryList split("/"$thePath);
  
  
$lastElement array_pop($aryList);
  
  
//print_r($aryList);
  
  
if ($lastElement == "admin") {
    
$isAdminPage true;
  }
  
  if (
in_array("admin"$aryList)) {
    
$isAdminPage true;    
  }
  
  if (
$isAdminPage) {
    print 
"This is an admin page";
  } else {
    print 
"This is not an admin page";
  }
  
?>
__________________
__________________________________________________ _
Wil Moore III, MCP | Integrations Specialist | Senior Consultant
Are You Listed...? | DigitallySmooth Inc.

Reply With Quote
  #4  
Old February 19th, 2003, 07:57 PM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
Quote:
Originally posted by jpenn
Well, you don't need a regexp for it. You can do ->

PHP Code:
if ( stristr$_SERVER['SCRIPT_NAME'] ), 'admin' ) {
/* do something */
} else {
/* not in string */



The above will work, but if you have a script called "pre_admin_page.php" or something similar, even though it isn't an admin page, it will get picked up as one.

Reply With Quote
  #5  
Old February 19th, 2003, 08:38 PM
Taelo Taelo is offline
5B's
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: PC, FL
Posts: 364 Taelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 26 sec
Reputation Power: 6
the way jpenn has it is exactly what I need. thanks for both quick replies though.

Reply With Quote
  #6  
Old February 20th, 2003, 02:04 AM
laidbak laidbak is offline
you know how we do
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jun 2002
Location: In Tha IE -- San Bernardino COUNTY
Posts: 788 laidbak User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 4 m 2 sec
Reputation Power: 7
Send a message via ICQ to laidbak Send a message via AIM to laidbak Send a message via MSN to laidbak Send a message via Yahoo to laidbak
Anytime

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > regex for path determination


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 

Iron Speed




© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway