Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: "J.O. Aho" Newsgroups: comp.lang.php Subject: Re: CTYPE Date: Sun, 25 Aug 2013 20:38:03 +0200 Lines: 65 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net rS1tMHdhtSjubsB458SLngzA9geB3tW96PWZdSw0t1MZBphg4C Cancel-Lock: sha1:6Fq8EuJKt3tl3MD/C2x4qd3/IUo= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130808 Thunderbird/17.0.8 In-Reply-To: Xref: csiph.com comp.lang.php:10618 On 25/08/13 19:51, Twayne wrote: > Hi all, > > I'm still working on the postal code issue, for Canada at the moment and > I'm still stuck. > > I've decided to try: > = See if it's alpha-numeric > = Create an array > = See if there is a space where it belongs > = Validate for digits in proper positions > = Since it's alpha-numeric, the 3 characters left must be Alphabetic. > If the validations work, keep going. > If not, halt & allow for a re-entry. > > The ctype statement will NOT work in any form and throws various errors > regardless of wher I place it or what I use s the var. Remove the entire > ctype, and everything works again. > > In code, this equates to, as best as I can: > --------------------------------------------------------------------------------------------------- > > IF(strlen($zip) === 7) { > echo "Zip appears to be Canadian .
"; > } > // ================== NOW LOOK TO SEE IF IT'S ALPHA-NUMERIC > > * if (ctype_alnum(str_split($zip,1)) { <---- Throws error [1] > * echo "Is Alpha Numeric."; > *} I assume you have just added the '*' first in the line to show which rows you are talking about. Simple maths will show your error, lets count your opening parentheses if (ctype_alnum(str_split($zip,1)) { 1 2 3 and now the number of closing parentheses if (ctype_alnum(str_split($zip,1)) { 12 So we get 3 opening parenthesis and 2 closing, this is what the "Parse error: syntax error, unexpected '{'" is about, you need to close all your parentheses. You know you will end up with loads of if cases if you keep on doing this instead of using a regular expression, this would speed it up and make your code a lot easier to read (case insensitive): if(preg_match("/^[a-z]\d[a-z] \d[a-z]\d$/i",$postcode)) { // this could be a valid Canadian postcode // just add what you need to do to check it against // Canadian Post, worst case use the "Find a post office" } -- //Aho