Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #10622

Re: CTYPE

From Twayne <nobody@spamcop.net>
Newsgroups comp.lang.php
Subject Re: CTYPE
Date 2013-08-25 15:28 -0400
Organization Aioe.org NNTP Server
Message-ID <kvdlrv$si2$1@speranza.aioe.org> (permalink)
References <kvdg6l$cni$1@speranza.aioe.org> <b7v18bFpg13U1@mid.individual.net>

Show all headers | View raw


On 2013-08-25 2:38 PM, J.O. Aho wrote:
> 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.

Correct.

>
> Simple maths will show your error, lets count your opening parentheses
>
> if (ctype_alnum(str_split($zip,1)) {
>     1           2         3

So Richard noted also. I even fired up another editor that shows parens 
et al by simply hoering a mouse over the tag. Damned if I didn't see it 
there either!
>
> 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.

It's so clearly visible to me now; no idea why I couldn't see it before.
>
>
> 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"
> }
>
>

I agree with you but I'm not useing regular expressions. 1 they're never 
clear to me, 2 I'm trying to avoid them as I have a couple in other 
cases where they actually cause noticeable slow-downs on even my Local 
Server, and magnitudes worse with I upload them to be "live", 3 there 
are so many ways to do the same thing in PHP my goal is to learn them 
and take notes of the most useful.
    So it's not just learning to code properly, it's also to learn 
better, less-code ways of doing things.

If you're so inclined you won't miss anything if you don't read the 
following but it might be well to explain a couple of things about the 
real reasons I'm having so much trouble here.

Mainly, I've been disabled and "retired" since 1994. In 2002 I suffered 
a serious brain concussion and lost many memories plus any ability w/r 
to Short Term Memory. I was even labeled "learning impaired" due to the 
concussion.  My doctor advised me that I might be able to get some of my 
old memories back, along with kicking the "learning disabled" tag, by 
"exercising" my brain.  He suggested since I liked computers that I find 
a way to use them to exercise the ol' gray matter.
     Currently I've regained most of my old memories and an no longer 
considered "learning disabled", but handling short-term memory issues is 
a real fight. IFF I handle them properly, I am able to retain memories, 
but it's often thwarted by not remembering to take the notes I need or 
otherwise record the information. That, on top of my disabilities (3 
types of arthritis, several myalgias and other sundry things, make it 
hard.  So, when I thought I was ready a few months ago, I decided to 
take on either VB net again, or PHP, both of which I knew at one point 
in time. I chose PHP because I did have some websites to my credit, and 
used a lot of old PHP code (well it's old now), so my overall goals now 
are to get to know PHP well enough to use it and also participate with 
responses on groups and forums such as this one.  And besides, VB code 
is expensive <g> since I was unable to work.

I don't give up easily and "Patience and Perseverence" is my mantra 
these days. It actually works! lol

I dislike saying all those things about myself, but I think it's fair to 
mention them as part of my gratitude for this group and several others.

Regards,

Twayne`

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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