[KLUG Members] PHP and regular expression problem

Adam Williams members@kalamazoolinux.org
30 May 2002 13:52:20 -0400


>Couple of ideas
>why not
>str_replace("0","",$serialnumber);  // stips all zeros

Because trailing zeros matter.

8AB001 = 8AB1
8AB010 = 8AB10
8AB010 != 8AB1

> or
>It looks like the errant/missing zeros are always in the middle, why not just
>add them when necessary?.
>$strlen=len($serialnumber);
>$prefix=substr(0,3,$serialnumber);
>$rest=$strlen-3;
>$suffix=substr(3,$rest,$serialnumber);
>$suffix=sprintf("%05s",$suffix);
>$newserialnumber=$prefix . $suffix;

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.