Forum Moderators: coopster

Message Too Old, No Replies

check folder name, if true, include this code

         

yellow_nemo

10:44 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



I need to check if the folder name is equal to for example, "Food", then do something, else don't do anything.

How do I do that? Thank you very much.

Longhaired Genius

10:58 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



$string = $_SERVER['PHP_SELF'];
if (preg_match("/\/food/", "$string")) {
do something;
}

yellow_nemo

11:21 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



can you explain to me what "/\/" means in front of "Food"? Thanks!

Longhaired Genius

11:28 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



The first / indicates the start of the regular-expression. The following \/ is the escaped forward-slash in the URL. The final / indicates the end of the regular-expression. You could have "/\/food\//" for completeness if the directory name is "food". You include the slashes so you don't match something inadvertently like "myfavouritefood.php".

yellow_nemo

11:44 pm on Jun 6, 2005 (gmt 0)

10+ Year Member



Thanks again! That works great!