Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z wyciagnieciem danych z pliku
dublinka
post
Post #1





Grupa: Zarejestrowani
Postów: 594
Pomógł: 66
Dołączył: 22.02.2008
Skąd: Dublin

Ostrzeżenie: (0%)
-----


Witam,
Mam plik z danymi. Dane zapisuja sie za kazdym razem do tego samego pliku i jest ich zawsze 10 czyli jesli zrobie to 10 razy bedzie tych linii 100 (logiczne chyba (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) )
Problem w tym ze nie potrafie przefiltrowac danych czyli pobrac konkretnych linii w petli do dalszej obrobki.

<?
$file = file('articles/3.dat');

for($i=0;$i<count($file);$i++)

{

print $file[$i] . '<br>';

}
?>


to mi pokazuje wszystko co mam w pliku ale jak zrobic zebym mogl w tej petelce pobrac 10 (10 to tylko przyklad bo chce pobrac wszystkie linie bo petla pobiera wszystko tyle ze konkretne dane z wpisu sa wlasnie podzielone co 10 linii) linii i mogl je obrabiac ?


Gdyby sie zapisywaly dane wszystkie w jednej linii z jakims separatorem np. chr(15) to prosta rzecz bo pobieram przez


list($dane1,$dane2,$dane3,$dane4,$dane5,$dane6,$dane7,$dane8,$dane9,$dane10) = split("[".chr(15)."]",$file[$i]);


i mam wtedy w kazdej zmiennej dane ale w tym przypadku nie wiem a teznie moge zmienic metody zapisu bo juz danych jest zbyt wiele i musialbym siedziec i zmieniac z miesiac sama strukture w plikach

Ten post edytował dublinka 22.02.2008, 08:36:43
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Kowalikus
post
Post #2





Grupa: Zarejestrowani
Postów: 111
Pomógł: 25
Dołączył: 23.07.2004

Ostrzeżenie: (0%)
-----


Nie o takie coś Ci chodziło?

  1. <?php
  2.  
  3. $FileToReadReply[] = 'imie';
  4. $FileToReadReply[] = 'email';
  5. $FileToReadReply[] = 'data';
  6. $FileToReadReply[] = 'temat';
  7. $FileToReadReply[] = 'tresc';
  8. $FileToReadReply[] = 'nick';
  9. $FileToReadReply[] = 'nr';
  10. $FileToReadReply[] = 'nr2';
  11. $FileToReadReply[] = 'id';
  12. $FileToReadReply[] = 'id2';
  13.  
  14.  
  15. $FileToReadReply[] = '2imie';
  16. $FileToReadReply[] = '2email';
  17. $FileToReadReply[] = '2data';
  18. $FileToReadReply[] = '2temat';
  19. $FileToReadReply[] = '2tresc';
  20. $FileToReadReply[] = '2nick';
  21. $FileToReadReply[] = '2nr';
  22. $FileToReadReply[] = '2nr2';
  23. $FileToReadReply[] = '2id';
  24. $FileToReadReply[] = '2id2';
  25.  
  26.  
  27. $FileToReadReply[] = '3imie';
  28. $FileToReadReply[] = '3email';
  29. $FileToReadReply[] = '3data';
  30. $FileToReadReply[] = '3temat';
  31. $FileToReadReply[] = '3tresc';
  32. $FileToReadReply[] = '3nick';
  33. $FileToReadReply[] = '3nr';
  34. $FileToReadReply[] = '3nr3';
  35. $FileToReadReply[] = '3id';
  36. $FileToReadReply[] = '3id3';
  37.  
  38. $FileToReadReply[] = '4imie';
  39. $FileToReadReply[] = '4email';
  40. $FileToReadReply[] = '4data';
  41. $FileToReadReply[] = '4temat';
  42. $FileToReadReply[] = '4tresc';
  43. $FileToReadReply[] = '4nick';
  44. $FileToReadReply[] = '4nr';
  45. $FileToReadReply[] = '4nr4';
  46. $FileToReadReply[] = '4id';
  47. $FileToReadReply[] = '4id4';
  48.  
  49. $FileToReadReply[] = '5imie';
  50. $FileToReadReply[] = '5email';
  51. $FileToReadReply[] = '5data';
  52. $FileToReadReply[] = '5temat';
  53. $FileToReadReply[] = '5tresc';
  54. $FileToReadReply[] = '5nick';
  55. $FileToReadReply[] = '5nr';
  56. $FileToReadReply[] = '5nr5';
  57. $FileToReadReply[] = '5id';
  58. $FileToReadReply[] = '5id5';
  59.  
  60. $FileToReadReply[] = '6imie';
  61. $FileToReadReply[] = '6email';
  62. $FileToReadReply[] = '6data';
  63. $FileToReadReply[] = '6temat';
  64. $FileToReadReply[] = '6tresc';
  65. $FileToReadReply[] = '6nick';
  66. $FileToReadReply[] = '6nr';
  67. $FileToReadReply[] = '6nr6';
  68. $FileToReadReply[] = '6id';
  69. $FileToReadReply[] = '6id6';
  70.  
  71. $FileToReadReply[] = '7imie';
  72. $FileToReadReply[] = '7email';
  73. $FileToReadReply[] = '7data';
  74. $FileToReadReply[] = '7temat';
  75. $FileToReadReply[] = '7tresc';
  76. $FileToReadReply[] = '7nick';
  77. $FileToReadReply[] = '7nr';
  78. $FileToReadReply[] = '7nr7';
  79. $FileToReadReply[] = '7id';
  80. $FileToReadReply[] = '7id7';
  81.  
  82.  
  83.  
  84.  
  85. $wyswietlaj=30; # podzial na kartki
  86. $ile_linkow=5; # -||-
  87.  
  88.  
  89.  
  90. $czytaj=0;
  91. $dalej=1;
  92.  
  93. $nr=$czytaj;
  94.  
  95.  
  96. $tmpArray = array();
  97. $u=1;
  98. for($i=$czytaj;$i<$czytaj+$wyswietlaj;$i++) 
  99. {
  100. if(!empty($FileToReadReply[$i]))
  101. {
  102. // print $FileToReadReply[$i]."<br>";
  103. if ($i % 10 == 0)
  104. {
  105.  
  106.  
  107.  
  108. $tmpArray[] = array();
  109. }
  110. $kk = $tmpArray[count($tmpArray )-1][] = $FileToReadReply[$i];
  111.  
  112.  
  113. }
  114.  
  115.  
  116.  
  117.  
  118. }
  119.  
  120.  
  121.  
  122. foreach ($tmpArray as $key=>$value) 
  123. {
  124. echo implode(' ', $value ) . '<br/>';
  125. }
  126.  
  127.  
  128. $out="";
  129. for($i=$dalej;$i<$dalej+$ile_linkow;$i++)
  130. {
  131. $k=($i-1)*$wyswietlaj;
  132. if($k<count($FileToReadReply))
  133. {
  134. if($k==$czytaj)
  135. {
  136. $out.=" [$i] ";
  137. }
  138. else{
  139. $out.=" <a class=\"l\" href=\"$PHP_SELF?id=".$HTTP_GET_VARS['id']."&czytaj=$k&dalej=$dalej\">[$i]</a> ";
  140. }
  141. }
  142. }
  143. if($dalej>1)
  144. {
  145. $cz=($dalej-1)*$wyswietlaj-$wyswietlaj;
  146. $dal=$dalej-$ile_linkow;
  147. print " <a class=\"l\" href=\"$PHP_SELF?f=".$HTTP_GET_VARS['id']."&czytaj=$cz&dalej=$dal\"><<<</a>";
  148. }
  149. else{
  150. print "<font class=\"gl_data\"><<< </font>";
  151. }
  152. print "<font class=\"gl_data\">".$out."</font>";
  153. if($k+$wyswietlaj<count($FileToReadReply))
  154. {
  155. $cz=$k+$wyswietlaj;
  156. $dal=$dalej+$ile_linkow;
  157. print " <a class=\"l\" href=\"$PHP_SELF?id=".$HTTP_GET_VARS['id']."&czytaj=$cz&dalej=$dal\">>>></a> ";
  158. }
  159. else{
  160. print "<font class=\"gl_data\"> >>></font>";
  161. }
  162.  
  163. ?>
Go to the top of the page
+Quote Post

Posty w temacie


Closed TopicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 11.10.2025 - 06:53