Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #10618
| 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" <user@example.net> |
| Newsgroups | comp.lang.php |
| Subject | Re: CTYPE |
| Date | Sun, 25 Aug 2013 20:38:03 +0200 |
| Lines | 65 |
| Message-ID | <b7v18bFpg13U1@mid.individual.net> (permalink) |
| References | <kvdg6l$cni$1@speranza.aioe.org> |
| 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 | <kvdg6l$cni$1@speranza.aioe.org> |
| Xref | csiph.com comp.lang.php:10618 |
Show key headers only | View raw
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 . <br />";
> }
> // ================== 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
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
CTYPE Twayne <nobody@spamcop.net> - 2013-08-25 13:51 -0400
Re: CTYPE Richard Yates <richard@yatesguitar.com> - 2013-08-25 11:21 -0700
Re: CTYPE Twayne <nobody@spamcop.net> - 2013-08-25 15:00 -0400
Re: CTYPE Richard Yates <richard@yatesguitar.com> - 2013-08-25 12:05 -0700
Re: CTYPE "J.O. Aho" <user@example.net> - 2013-08-25 20:38 +0200
Re: CTYPE Twayne <nobody@spamcop.net> - 2013-08-25 15:28 -0400
Re: CTYPE Richard Yates <richard@yatesguitar.com> - 2013-08-25 13:16 -0700
Re: CTYPE Twayne <nobody@spamcop.net> - 2013-08-26 11:49 -0400
Re: CTYPE Christoph Michael Becker <cmbecker69@arcor.de> - 2013-08-25 22:19 +0200
Re: CTYPE Twayne <nobody@spamcop.net> - 2013-08-26 12:15 -0400
Re: CTYPE Fiver <numeralfive@gmail.com> - 2013-08-25 22:42 +0200
Re: CTYPE Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2013-08-26 10:25 +0200
Re: CTYPE The Natural Philosopher <tnp@invalid.invalid> - 2013-08-26 09:29 +0100
Re: CTYPE Twayne <nobody@spamcop.net> - 2013-08-26 12:37 -0400
Re: CTYPE Norman Peelman <npeelman@cfl.rr.com> - 2013-08-25 15:11 -0400
Re: CTYPE Tim Streater <timstreater@greenbee.net> - 2013-08-25 23:04 +0100
Re: CTYPE THREAD RESOLVED Twayne <nobody@spamcop.net> - 2013-08-25 15:35 -0400
Re: CTYPE THREAD RESOLVED Fiver <numeralfive@gmail.com> - 2013-08-26 20:07 +0200
Re: CTYPE THREAD RESOLVED The Natural Philosopher <tnp@invalid.invalid> - 2013-08-26 20:19 +0100
Re: CTYPE THREAD RESOLVED Fiver <numeralfive@gmail.com> - 2013-08-26 22:51 +0200
Re: CTYPE THREAD RESOLVED Jerry Stuckle <jstucklex@attglobal.net> - 2013-08-26 16:57 -0400
Re: CTYPE THREAD RESOLVED Twayne <nobody@spamcop.net> - 2013-08-27 17:20 -0400
Re: CTYPE THREAD RESOLVED Jerry Stuckle <jstucklex@attglobal.net> - 2013-08-27 19:47 -0400
Re: CTYPE THREAD RESOLVED Tim Streater <timstreater@greenbee.net> - 2013-08-26 22:07 +0100
Re: CTYPE THREAD RESOLVED Twayne <nobody@spamcop.net> - 2013-08-28 08:49 -0400
Re: CTYPE THREAD RESOLVED Twayne <nobody@spamcop.net> - 2013-08-27 17:18 -0400
csiph-web