Search code examples
phpswitch-statementcharactercaseany

Look for any characters in PHP switch cases


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.


Solution

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