Forum Moderators: coopster

Message Too Old, No Replies

use preg match in switch case

case is not matching whatsoever

         

phparion

6:12 am on Jun 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Hi

I want to write a switch case, which stand true for all such values which has "rotate.php" in it, it is optional to have a query string with the page too. i want to match all such cases, for this i tried the following,


case preg_match("/rotate\.php(\?)?[\w\d=]*/",$bx[3]):

but it does not match even rotate.php in the url. i get correct value in $bx[3] but my regex is not working.

i want to match ,

starting with rotate.php following by anything.

even this one doesn't work

case preg_match("/^rotate/",$bx[3]):

means , start with rotate followed by anything

cameraman

6:45 am on Jun 20, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Remember that preg_match returns either zero or one. So about the only way to make this work is to do:
switch(1) {
case preg_match("/rotate\.php(\?)?[\w\d=]*/",$bx[3]):
.
.
The pattern seems to work when used by itself.