[KLUG Members] PHP and regular expression problem
Adam Williams
members@kalamazoolinux.org
Thu, 30 May 2002 14:23:26 -0400 (EDT)
>>8AB00610 -> 8AB610
>>8AB00611 -> 8AB611
>>8AB00001 -> 8AB1
>>Then natural ordering will still worth even with absent zeros.
>Won't that sort 8AB10 before 8AB2?
Thats "Ordinal Ordering"
>Or does "natural ordering" mean something different in PHP that I
>don't know about?
? "Natural Ordering" is "Natural Ordering"
http://naturalordersort.org/
$arr2 = array("img12.png","img10.png","img2.png","img1.png");
usort($arr2,"strnatcmp");
print_r($arr2);
will produce
Array
(
[0] => img1.png
[1] => img2.png
[2] => img10.png
[3] => img12.png
)
>I'm assuming you always have three characters before the zeroes?
>Sounds like you don't want
>8AB601 -> 8AB61
>In perl I'd just do s/^(.{3})0+/$1/ which strips any zeroes after
>the first three chars.
Hmmm. Thats usually true, only some are like 12CL????. Really no rhyme
or reason. I think I'll just toss ones out that aren't the same length,
and make a list of the ones that can't be matched. Make the bald monkeys
key them all back in.