-2

I need to have a case that checks for a few first characters, and then accept any other 7 characters. Something like this:

DN98???????

I tried doing it like this:

        case 'DN98'+'[a-zA-Z0-9]':
            $theme = 'correct-page';
            break;

but it only makes every url go to the "correct-page", not only those starting with DN98. I also tried:

        case 'DN98????????':
            $theme = 'correct-page';
            break;

But it doesn't do anything, just makes typing that code go to the default case, also tried the same but with "*", didn't work.

Anyone might help me out? I'm not that good with PHP.

fenbekus
  • 3
  • 1
  • 5
    That's not what `switch` does. You want `preg_match` in an `if..else`. – deceze Oct 12 '17 at 08:49
  • You could try with `preg_match()`: an answer here [enter link description here](https://stackoverflow.com/questions/4043741/regexp-in-switch-statement) – th3fr33man Oct 12 '17 at 08:55
  • Thank you guys, it worked, also is there an option to limit the amount of "any" characters to 7? It's not as important, but would be useful – fenbekus Oct 12 '17 at 09:01

1 Answers1

0

To get the first 7 characteres you can use the regex like this ^[a-zA-Z0-9]{7} or [a-zA-Z0-9]{7}$ for the last 7.

th3fr33man
  • 60
  • 1
  • 5