Page 1 of 1

To regex, or not to regex?

Posted: Mon Dec 15, 2003 4:24 pm
by uberpolak
Whole mess of crap to deal with, try to stay with me here...

The server I'm working with doesn't allow any htaccess changes, so to keep URLs somewhat user-friendly, I'm extracting the query string, and using what's in there as a variable, rather than full-out URL variable passing.

i.e. ?home instead of ?page=home

That much I have set up without a problem. The problem is when there is another variable in the query string (which happens if someone wants to switch the stylesheet). The query string ends up looking like this:

?home&s=1

It picks up s=1 okay, but doesn't know what to do with home, and the query string is taken as "home&s=1," which isn't a valid page, obviously. What I want to do is have it find "home" (I suppose it would consider this a variable without a value).

Having very little experience with regular expressions, I'm not sure if they have the capability I'm looking for (although, from what I understand, it makes sense that they would). What I'm asking is, how would I set up the expression to search for an unknown value?

Lot of explanation for one question, huh?

Posted: Mon Dec 15, 2003 4:50 pm
by uberpolak
I achieved the desired result by parsing the query string, and going throught the variables with foreach(), but the code seems like it could be much more efficient. This isn't a super-high priority anymore, but if anyone has a solution I'd still be interested.

Posted: Mon Dec 15, 2003 6:40 pm
by McGruff
You could have a query string like:

http://www.mysite.com/index.php?page=forum/posts/233/2

Explode $_GET['page'] to grab the args.

As well as making URLs more user friendly, parsing the query string makes it harder for tamperers to glean the function of each GET var.

Posted: Mon Dec 15, 2003 6:56 pm
by dull1554
i hate "tamperers", they tend to make my job far harder then it should every be.......

Posted: Tue Dec 16, 2003 2:55 am
by twigletmac
You could also grab everything before the first & (check the user comments):
http://php.net/manual/en/function.strstr.php

Mac