Re: Check input against list
| From: | Daniel Convissor | Date: | Wed, 02 Aug 2000 02:06:06 +0000 |
| Subject: | Re: Check input against list | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-9613@lists.php.net to get a copy of this message | ||
Hey Y'all:
Chris Adams wrote:
>
> > I have a couple input fields that require ISO state and country codes.
> >
> > Is there some way to check that an input string is one of N possibilities,
> > where N is a large-ish number?
I do something similar in one of my forms/scripts.
> $States = array("CA", "AZ", "HI");
>
> if (isset($States[$UserEnteredState])) echo "Yes, we have service there!";
>
> in_array() can be used very similarly.
Now, THAT'S an interesting idea.
In my scripts, I'm doing a lookup on a text file to find some information
related to the ISO codes. I store the codes and related info in a CSV (comma
separated values) file. Then, I loop through the file with fgetcsv(). If a
match happens, I store the related info and break out of the loop. So, if in
the lookup doesn't find a match, I know the code is invalid.
Enjoy,
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
More than just answers. Solutions. (SM)
http://www.analysisandsolutions.com/
4015 7 Av #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409