note 83113 added to control-structures.switch

From: Date: Sat, 10 May 2008 18:34:21 +0000
Subject: note 83113 added to control-structures.switch
Groups: php.notes 
Request: Send a blank email to php-notes+get-139242@lists.php.net to get a copy of this message
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 ---- Server IP: 217.174.223.124 Probable Submitter: 68.53.28.212 ---- Manual Page -- http://www.php.net/manual/en/control-structures.switch.php Edit -- https://master.php.net/note/edit/83113 Del: integrated -- https://master.php.net/note/delete/83113/integrated Del: useless -- https://master.php.net/note/delete/83113/useless Del: bad code -- https://master.php.net/note/delete/83113/bad+code Del: spam -- https://master.php.net/note/delete/83113/spam Del: non-english -- https://master.php.net/note/delete/83113/non-english Del: in docs -- https://master.php.net/note/delete/83113/in+docs Del: other reasons-- https://master.php.net/note/delete/83113 Reject -- https://master.php.net/note/reject/83113 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#139242) next »