-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.

3
  • 5
    That's not what switch does. You want preg_match in an if..else.
    – deceze
    Commented Oct 12, 2017 at 8:49
  • You could try with preg_match(): an answer here enter link description here
    – th3fr33man
    Commented Oct 12, 2017 at 8: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
    Commented Oct 12, 2017 at 9:01

1 Answer 1

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.

Not the answer you're looking for? Browse other questions tagged or ask your own question.