Jump to content
php.lv forumi

php un .txt


Erglis

Recommended Posts

Sveiki, Atnācu pie jums ar mazu lūgumu. Varbūt arī pēc skriptiņa ja būsat tik laipni !

 

mana web folderi atrodas piem. dokuments.txt kuru es gribētu atēlot web'a..

dokuments.txt saturs ir top15 un izskatas šādi:

 

X "Erglis" 3 19 50 0

X "[b-TeaM] Tr!x*" 3 45 80 17

X "Erglis" 4 14 20 0

X "[b-TeaM] Tr!x*" 4 58 20 33

X "[b-TeaM] Mc" 7 24 80 10

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

 

Gala rezultāts:

Niks Laiks CP

1)Erglis 3:19:50 0

2)[b-TeaM] Tr!x* 3:45:80 17

3)Erglis 4:14:20 10

4)[b-TeaM] Tr!x* 4:58:20 33

5)[b-TeaM] Mc 7:24:80 10

 

Tops tiek papildināts automatiski un vietas var mainiities...

Link to comment
Share on other sites

$saturs=file('dokuments.txt');
for($i=0;$i<count($saturs);$i++)
{
 $rinda=explode(' ', trim($saturs[$i]));
 $vieta=$i+1;
 echo $vieta.')'.str_replace('"', '', $rinda[1]).' '.$rinda[2].':'.$rinda[3].':'.$rinda[4].' '.$rinda[5].'<br />';
}

Link to comment
Share on other sites

Nolasīšanai precīzāk būtu

 

$file = file('dokuments.txt');
$data = Array();
$i = 0;
foreach($file as $key => $value) {
  $value = explode('"', $value);
  if (count($value) != 3) {
  continue;
  }
  $value['Niks'] = $value[1];
  if ($value['Niks'] == 'X') continue;
  $value[2] = explode(' ', trim($value[2]));
  $value['Laiks'] = $value[2][0] . ':' . $value[2][1] . ':' . $value[2][2];
  $value['CP'] = $value[2];
  $i++;
  echo $i . ') ' . $value['Niks'] . ' ' . $value['Laiks'] . ' ' . $value['CP'];
}

Link to comment
Share on other sites

Ar pregu smukāk būs...

 

/\"(.+?)\"\s([\d])\s([\d])\s([\d])\s([\d])/

 

\s vai \S neatceros, manuālī paskaties...

 

ja veel kko no taa prega saprastu :P kur tas jaaraxta ieksaa??? :?

 

un paldies GedroX`am un MakaTaNaw...

Link to comment
Share on other sites

Laikam kautkā tā:

 

<?php
$file = file('dokuments.txt');
$data = Array();
$i = 0;
foreach($file as $key => $value) {
$value = trim($value);
$value = preg_replace('/^X "X" .*$/', '', $value);
if (preg_match('/^X "(.+)" (\d+) (\d+) (\d+) (\d+)$/', $value)) {
	$i++;
  echo preg_replace('/^X "(.+)" (\d+) (\d+) (\d+) (\d+)$/', $i . ') $1 $2:$3:$4 $5', $value) . '<br />';
 }
}

?>

Link to comment
Share on other sites

a kā tu domā to pielietot vari paskaidrot, mani ieintrģēji :)

nu ir taada jauka lietinja kaa top15 :))))) vnk gribaas kreedz serverim mazu topinju ne tikai ieksh cs servera, bet arii web lapinjaa... :) buusju ljoooti prieciigs ja kaads paliidzeees, bet nu meeginaasju kko arii pats burt... tikai nesanaak =/

Link to comment
Share on other sites

Zinu, ka ir top15, bet kur tur var dabūt šādu: X "Erglis" 3 19 50 0

X "[b-TeaM] Tr!x*" 3 45 80 17

X "Erglis" 4 14 20 0

X "[b-TeaM] Tr!x*" 4 58 20 33

X "[b-TeaM] Mc" 7 24 80 10

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

Pasaki, būšu ļoti pateicīgs, jo man sanāca ar taviem skaitļiem kko sakinīt, bet kur tu rauji šos skaitļus, kurā mapē

X "Erglis" 3 19 50 0

X "[b-TeaM] Tr!x*" 3 45 80 17

X "Erglis" 4 14 20 0

X "[b-TeaM] Tr!x*" 4 58 20 33

X "[b-TeaM] Mc" 7 24 80 10

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

X "X" 9999999 0 0 9999999

Link to comment
Share on other sites

×
×
  • Create New...