FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » CTYPE
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: CTYPE [message #182669 is a reply to message #182665] Sun, 25 August 2013 19:28 Go to previous messageGo to previous message
bill is currently offline  bill
Messages: 310
Registered: October 2010
Karma:
Senior Member
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`
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Re: korean character sets
Next Topic: Android app Developers requirements
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 01 07:15:15 GMT 2024

Total time taken to generate the page: 0.04501 seconds