[KLUG Members] PHP and regular expression problem

Adam Williams members@kalamazoolinux.org
Thu, 30 May 2002 17:03:38 -0400 (EDT)


>>>>It looks like the errant/missing zeros are always in the middle, why not just
>>><much deleted>
>>>Unfortunately I don't know how many there should be.  While all the
>>>examples are gave are of a consistent length, the integer portion of the
>>>number actually varies in length.
>>Simply put, it looks like the serial number contains several fields compounded
>>together.  The solution seems to lie in separating and regularizing the field you
>>want to analyze.
>>You call them integers, so maybe
>>intval($suffix)
>>and compare on the result
>>would work.
>Is there a php function which will return the index order of an array that would
>place it in some sorted order? If so, this problem becomes both trivial in nature
>and has very general solution. I'm sure no one wants to go back and rework this
>thing if the meanings, intervals or other properties change. It is desirable to
>have a solution that has those properties, without getting involved in the nature
>of the data.

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).

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

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

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.  Something like 
"serial string" would be much more accurate and probably make everyones 
lives easier.  Of course, if I could talk payroll into dropping some zeros 
of their paychecks the message would probably get through clear 
enough.....

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).  "Natural Ordering" is 
the type of ordering usually used by those biological things called 
people.  And so "Natural Ordering" works 99.44% of the time to determine 
if some stupid human meant this to be before or after something else.  It 
is a very nice algorythm and is supported by PHP (default).  It is one of 
the reasons I'm so fond of PHP.