[KLUG Members] PHP and regular expression problem

bill members@kalamazoolinux.org
Thu, 30 May 2002 17:25:42 -0400


No sense looking for answers until you first define the problem; which you're doing
now.  More below

Adam Williams wrote:

> Exactly,  this is really reflective of a business problem -
>
> 1. We don't "know" the format of serial numbers,  only the manufacturer
> does (or so one hopes).

It must have some format if that word means anything.  Just a matter of learning (and
parsing) it.

> 2. Long standing formats can change tomorrow,  and there won't be any
> fore-warning.

Hence you can probably only create a solution for today's problem.  Heck, you're
assuming the serial number can be entered with a keyboard.  Change to cuneiform (reed
stylus on clay tablets) and it's unlikely anybody's program could have covered it in
advance.

> 3. Every manufacturer uses different "structure" in their serial numbers.

Relational database of manuf. & serial # formats.

> The most pesky problem is -
>
> 4. The word "number" in the phrase "serial number" makes the not so bright
> think they are a "number" and thus, zeros don't count.

You yourself called the sortable section an integer.  Quite rightly, I believe.

> However, serial numbers still have "ranges" like numbers.  So when we
> perform service on a unit of type "MD40" the serial numbers 2CL00001
> to 2CL00554 use one type of filter and serial numbers 2CL00555 to
> 2CL99999 use another type of filter (for example).

Note the range here.  The range portion -is- a number.  Cut off the first three
characters and you have a decimal (base 10) number of up to five numerals.  That range
is from 00001 to 99999.  Use intval() on that number to remove the preceding zeros and
you have a simple integer, sortable and "eval-uable" for whatever you want.  e.g.:

if  ($suffix  <= 554) {
    // use one type of filter
} else if  ($suffix > 554) {
    // use another type of filter
} else {
    // call 911
}

kind regards,

bill