Re: Normalized Numbers

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Brian P. Giroux wrote:
> 
> Jochem Maas wrote:
>> Brian P. Giroux wrote:
>>> I am just learning PHP and as a practical exercise I've been working on
>>> a set of functions to process and manipulate what I call "normalized
>>> number" (ISBNs, EANs, UPCs, etc...)
>>>
>>> My ultimate goal is to create a normnum class and child classes for the
>>> different types of numbers.
>>>
>>> Because of my line of work, I am mostly interested in ISBN-10s,
>>> ISBN-13s, EANs and UPCs, but it can also be expanded to credit card
>>> numbers, Canadian Social Insurance Numbers, and many more.
>>>
>>> So far I have functions to validate ISBN-10s and EANs although I've run
>>> into a bit of a wall with the digit_sum function as explained in the B:
>>> section of that functions header comments.
>> if you want to turn the direction around reverse the string before
>> you start the loop:
>> 	http://php.net/manual/en/function.strrev.php
> 
> I never thought of turning the string around.

you can't be expected to know everything, especially not when starting out ...
that said just browsing the manual for it's own sake is to be recommended,
not exactly a rollercoaster read but you'll be surprised at the ammount of stuff
you can pick up.

> 
>> personally I would turn the string into an array of chars (which you can then also
>> reverse as need be) and then do a foreach loop on it ('array index'+1 can be used
>> to determine position) ... personal preference. anyway take a look at these functions:
> 
> Is there a reason for converting to an array. It seems to me that the
> conversion would add more overhead.

noo not really - more of a preference on my part, I prefer foreach() to for()
when I have the choice and I usually find that the code is compacter when using
foreach(), it also [often] mitigates the need to keep track of a counter variable.

> 
>> 	http://php.net/manual/en/function.str-split.php
>> 	http://php.net/array_reverse
>> 	http://php.net/foreach
>>> If anyone can help me out with that or provide any other advice about
>>> the rest of it, I'd be grateful.
>> keep commenting all your code to that extent! you do us proud :-)
> 
> Thanks, I don't have much choice. I can only work on this every few
> days, sometimes every few weeks. If I don't comment I find that I forget
> what I was doing :(

making sure your comments are accurate is paramount, undoubtly your need to
comment things will become less as your skills improve.

as Roman pointed out comments have their downside too - I'm certainly taking
what he's said and am digging into his Testilence tool.

at the end of the day it's all about learning, improving and sharing your
skills :-)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux