PDA

View Full Version : Using preg_match to find if string equals required pattern, or required+optional pattern?


FethrdWlf
07-16-2012, 01:14 AM
http://new.kn3rdmeister.com
I have buttons at the top of my website that link to other pages of the website (only the first two are in use currently). The toolbar is a single PHP page that I include in every page. In the toolbar page, PHP checks the current directory the user is in, and then either displays a "link button", or a "current page" button, so that the user can see where they are.

I'm running into a problem though. I have an if statement checking the value of a variable that contains the current directory.

...
if($curdir == "/category/blog/"){...}else{...}
...

That'll work if the user is in the default directory of the blog, but if they are in let's say "/category/blog/page/3/", it doesn't quite work out. The script needs to check to see that they are definitely at least in the default blog directory, or even deeper in.

I know I can use preg_match to do what I need to do, but I don't know how to do it. Thank you for your time 8)

EDIT: also I'm sure there's a cleaner way to check the directory and display from there, but I'll open a new thread for that if need be.