note 83113 rejected from control-structures.switch by nlopess

From: Date: Sat, 10 May 2008 22:09:40 +0000
Subject: note 83113 rejected from control-structures.switch by nlopess
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-139257@lists.php.net to get a copy of this message
Note Submitter: sl at mojomediapros dot com ---- PHP newbie, wondering if it is possible to use patterns, or some other mechanism, with switch statements, to evaluate various ways that a user might have entered the information. Specifically, I am trying to assign themes (css style sheets) based on the company name that a user enters. So a user might enter "ABC Company", "ABC", "ABC Co", "abc company", "The ABC Company", etc. and I want all these to evaluate as true in the switch statement. Granted I can create single switch statements for each: switch ( $acct['Company'] ) { case "ABC Company" : $acct['Theme'] = 25; break; case "ABC" : $acct['Theme'] = 25; break; case "ABC Co" : $acct['Theme'] = 25; break; case "abc company" : $acct['Theme'] = 25; break; case "The ABC Company" : $acct['Theme'] = 25; break; default: $acct['Theme'] = 0; break; } I know there must be more efficient ways of handling this; but my PHP chops aren't quite there yet. I was hoping to do something like (*ABC*|*abc*) to catch all the obvious entries, but not sure that patterns can be used w/switch statements, and if they can, I'd appreciate a leg up on the syntax. Any suggestions/comments, would be much appreciated. SL

« previous php.notes (#139257) next »