so i had txt with this look like text:
Dragon_Scale_Leggings|L|46|Poison|30lvl|12% Poison resistance|imagesb|http://img174.imageshack.us/img174/9527/04e2dragonscaleleggingsqu9.gif|imagese|specialib|to make - 79 Dragon Scales|specialie|creditsb|Shadowsoul|KaaLi|creditse|
Dragon_Scale_Gauntlets|G|37|Poison|30lvl|10% Poison resistance|imagesb|http://img187.imageshack.us/img187/8610/04e1dragonscalegauntletcc1.gif|imagese|specialib|to make - 44 Dragon Scales|specialie|creditsb|Shadowsoul|KaaLi|creditse|
Dragon_Scale_Platemail|A|55|Poison|30lvl|19% Poison resistance|imagesb|http://img153.imageshack.us/img153/6308/04e0dragonscaleplateir7.gif|imagese|specialib|to make - 126 Dragon Scales|specialie|creditsb|Slither|Shadowsoul|Uppercut|KaaLi|Redking|Lefix|creditse|
Dragon_Scale_Shield|S|23|Poison|35lvl|12% Poison resistance|imagesb|http://img246.imageshack.us/img246/6817/04dfdragonscaleshieldea3.gif|imagese|specialib|to make - 90 Dragon Scales|specialie|creditsb|Shadowsoul|Uppercut|Redking|Lefix|creditse|
Decorative_Helm|H|?|Magical|?|?|imagesb|http://img59.imageshack.us/img59/6186/0433decorativehelmlq3.gif|imagese|specialib||specialie|creditsb||creditse|
Chainmail_Gloves|G|12|Magical|10lvl|None|imagesb|http://img153.imageshack.us/img153/5268/0282chainmailglovesld7.gif|imagese|specialib||specialie|creditsb||creditse|
Chainmail_Leggings|L|16|Magical|10lvl|None|imagesb|http://img136.imageshack.us/img136/5955/0262chainmailleggingsrz7.gif|imagese|specialib||specialie|creditsb||creditse|
Chainmail|A|20|Magical|7lvl|None|imagesb|http://img91.imageshack.us/img91/3690/0103chainmailzh7.gif|imagese|specialib||specialie|creditsb||creditse|
Chainmail_Coif|H|8|Magical|5lvl|None|imagesb|http://img294.imageshack.us/img294/5606/00f8chaincoifpk9.gif|imagese|specialib||specialie|creditsb||creditse|
Conjurerers_Robe|A|24|Cold and Electrical|40lvl, 40int|9% C&E resistance|imagesb|http://img357.imageshack.us/img357/7053/conjurerersrobesx4br6.png|imagese|specialib||specialie|creditsb|Locke|Sir Mice|Thetyrant|Sargeras|KaaLi|creditse|
Black_Gauntlets|G|40|Magical|75str,EA|None|imagesb|http://img201.imageshack.us/img201/5158/0289blackgauntletsqn4.gif|imagese|specialib||specialie|creditsb|Haze|creditse|
i was forced to sort this txt file by 4 column
to make it look like 100, 90, 50, 10, 9, 5, 3, None, ?
idea how to sort: take all info from txt file to 2 dimentional array . while taking info from file it counts how many symbols has each element in 4th column and writes it to $ci[$k] . then it uses burble method with this conditions:
$mas[$i][4]!="" && $mas[$ii][4]!="" && $mas[$i][4]!=$mas[$ii][4] && (($ci[$i] > $ci[$ii]) || ($mas[$i][4] > $mas[$ii][4] && $ci[$i]==$ci[$ii]))
after it sorted time to write to file. i stacked at conditions for a hours >.<
so here script (code) which i made in one day period ^^
$byla="armors22.txt";
$byla=file($byla);
$sk=sizeof($byla);
$byla2=fopen("armors.txt", "w");
$k=0;
while($sk>0)
{
$mas[$k]=explode("|",$byla[$sk-1]);
for($ch=0;$ch<7;$ch++)
{
if($mas[$k][4][$ch]=="" || $mas[$k][4][$ch]==" " || $mas[$k][4][$ch]=="," || $mas[$k][4][$ch]=="?" || $mas[$k][4][$ch]=="s" || $mas[$k][4][$ch]=="N" || $mas[$k][4][$ch]=="l" || $mas[$k][4][$ch]=="i") { $ci[$k]=$ch; break; }
}
$k++;
$sk--;
}
//mas[0-sk][0-creditse] ; ci[0-sk].
$sk=sizeof($byla);
$pak=0;
$pakeitimas=1;
while($pakeitimas==1)
{
$pakeitimas=0;
for($i=0;$i<$sk;$i++)
{
$ii=$i+1;
if($mas[$i][4]!="" && $mas[$ii][4]!="" && $mas[$i][4]!=$mas[$ii][4] && (($ci[$i] > $ci[$ii]) || ($mas[$i][4] > $mas[$ii][4] && $ci[$i]==$ci[$ii])))
{
$k=0;
foreach($mas[$i] as $item)
{
$a[$i][$k]=$item;
$k++;
if($k==70) break;
}
$k=0;
foreach($mas[$ii] as $item)
{
$mas[$i][$k]=$item;
$k++;
if($k==70) break;
}
$k=0;
foreach($a[$i] as $item)
{
$mas[$ii][$k]=$item;
$k++;
if($k==70) break;
}
$pa=$ci[$i];
$ci[$i]=$ci[$ii];
$ci[$ii]=$pa;
$pakeitimas=1;
}
}
$pak++;
}
echo " $pak ";
for($i=0;$i<$sk;$i++)
echo $i.") ".$mas[$i][0]." ".$mas[$i][4]."
";
$sk=sizeof($byla);
while($sk>-1)
{
$i=0;
$a=$mas[$sk][$i];
fputs($byla2, "\n$a|");
while($mas[$sk][$i]!=creditse)
{
$i++;
$a=$mas[$sk][$i];
fputs($byla2, "$a|");
if($i==70) break;
}
$i++;
$a=$mas[$sk][$i];
fputs($byla2, "$a|");
$sk--;
}
fclose($byla2);
?>
No comments:
Post a Comment