|
Posted by roN on 11/12/52 11:28
Stefan Rybacki wrote:
> roN wrote:
>> Stefan Rybacki wrote:
>> sorry didn't get that:
>>
>>>The first problem is the weird filename format you're using
>>>(...-05-09-13,14). The second day value doesn't help here ;)
>>>
>>>Ok try this regular expression
>>>
>>>/([^-]*)-([^.]*)\.jpg/i
>>
>> and what should I do with it?
>>
>>>use a match all function and you will retrieve an array with the number
>>>and the date seperated. Then change the compare function to first compare
>>>the date and only if both dates are the same compare the number, thats
>>>all.
>>
>> what do you mean with 'match all function'
>> Ok, I've tried it like below, but doesn't really work,
>> $rega[1] is always ""
>> and in $rega[0] is the whole filename... :(
>> [Code]
>> function mycompare ($a, $b)
>> {
>> $rega=split("/([^-]*)-([^.]*)\.jpg/i",$a);//extract date and
>> filename $regb=split("/([^-]*)-([^.]*)\.jpg/i",$b);//extract date
>> and filename echo $rega[0]." [0]<br>\n";
>> echo $rega[1]." [1]<br>\n";
>>
>> if($rega[1]==$regb[1]) //compare date
>> {
>> //first check for search text in $a and $b
>> $isInA=(strpos($a,'p')!==false);
>> $isInB=(strpos($b,'p')!==false);
>>
>> //so if $isInA==$isInB then compare alphabetical
>> //but reverse first a & b
>> $a=strrev($a);
>> $b=strrev($b);
>> if ($isInA == $isInB)
>> {
>> if ($a == $b)
>> return 0;
>> return ($a > $b) ? 1 : -1;
>> }
>> else
>> {
>> //the one that is true comes first
>> return ($isInA) ? -1:1;
>> }
>>
>> return 0;
>> }
>> else
>> {
>> return 0;
>> }
>> }
>> [/Code]
>> Sorry, but I'm quite new to that stuff.
>
> I guess you are ;)
yup :)
And I'm even very thakful that you're helping me, to me improve my
knowledge :)
Ok, my Function looks now like this:
function mycompare ($a, $b)
{
preg_match("/([^-]*)-([^.]*)\.jpg/i",$a,$rega);//extract date and filename
preg_match("/([^-]*)-([^.]*)\.jpg/i",$b,$regb);//extract date and filename
if($rega[2]==$regb[2]) //compare date
{
//first check for search text in $a and $b
$isInA=(strpos($a,'p')!==false);
$isInB=(strpos($b,'p')!==false);
//so if $isInA==$isInB then compare alphabetical
//but reverse first a & b
//$a=strrev($a);
//$b=strrev($b);
if ($isInA == $isInB)
{
if ($a == $b)
return 0;
return ($a > $b) ? 1 : -1;
}
else
{
//the one that is true comes first
return ($isInA) ? -1:1;
}
return 0;
}
else
{
return 0;
}
}
But I get a srange order like:
p1010002-05-09-12.jpg
p1010003-05-09-12.jpg
p1010004-05-09-12.jpg
p1010005-05-09-12.jpg
p1010006-05-09-12.jpg
p1010007-05-09-12.jpg
p1010008-05-09-12.jpg
p1010009-05-09-12.jpg
p1010012-05-09-12.jpg
p1010016-05-09-12.jpg
p1010021-05-09-12.jpg
p1010027-05-09-03.jpg
p1010024-05-09-12.jpg
p1010002-05-09-04.jpg
p1010025-05-09-12.jpg
p1010028-05-09-07,08,09.jpg
p1010028-05-09-12.jpg
p1010023-05-09-04.jpg
p1010029-05-09-12.jpg
p1010048-05-09-07,08,09.jpg
p1010014-05-09-05,06.jpg
to be continued...
why are there some unsorted Values between?
and why doesn't it start with 05-09-03?
is 0>1??? how to change.
Thank you!
--
chEErs roN
I'm root, I'm allowed to do this! ;)
keep on rockin'
[Back to original message]
|