Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Kasowanie
esesjot
post
Post #1





Grupa: Zarejestrowani
Postów: 21
Pomógł: 0
Dołączył: 26.07.2004

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


Co mam zrobić by na stronie wyświetlały się linijki pobrane z pliku text.txt i żebym mógł sobie wybrać jedną z nich i wykasować? (IMG:http://forum.php.pl/style_emoticons/default/guitar.gif)
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
tiraeth
post
Post #2





Grupa: Przyjaciele php.pl
Postów: 1 789
Pomógł: 41
Dołączył: 30.10.2003
Skąd: Wrocław

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


a ja byłem jeszcze lepszy i napisałem klasę (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif)

-------- plik: class.deleteLine.php --------
  1. <?php
  2. #####################
  3. # KLASA DO USUWANIA #
  4. # DANEJ LINIJKI W #
  5. # PLIKU TEKSTOWYM #
  6. #####################
  7. # autor : tiraeth #
  8. #####################
  9.  
  10. class readFile()
  11. {
  12. var $lines = 0;
  13. var $filename;
  14. var $opened = array();
  15.  
  16. function readFile($file)
  17. {
  18. $this->filename = $file;
  19. $this->opened = file($this->filename);
  20. }
  21.  
  22. function deleteLine($line)
  23. {
  24. if($this->deletedLine)
  25. {
  26. unset($this->deletedLine)
  27. }
  28.  
  29. $this->selectedLine = $line--;
  30.  
  31. $data = file($this->filename;
  32.  
  33. unset($data[$this->selectedLine]);
  34.  
  35. $data = implode(&#092;"n\", $data);
  36.  
  37. $handle = fopen($this->filename, &#092;"w\");
  38. fputs($handle, $data, strlen($data));
  39. fclose($handle);
  40.  
  41. $this->deletedLine = $this->selectedLine;
  42. }
  43.  
  44. function deletedMessage()
  45. {
  46. return 'Line number <b>'.$this->deletedLine.'</b> has been deleted!';
  47. }
  48. }
  49. ?>


-------- plik: kasuj.php --------
  1. <?
  2. include('class.deleteLine.php');
  3.  
  4. if(!$_GET['line'])
  5. {
  6. $plik=file(&#092;"plik.txt\");
  7. foreach($plik as $plik)
  8. {
  9. $i++;
  10. echo'<span style=\"color:silver\">'.$i.'</span> '.$plik.'[<a href=\"kasuj.php?line='.$i.'\">x</a>]';
  11. }
  12. }
  13. else
  14. {
  15. $plik = new readFile(&#092;"plik.txt\");
  16. $plik->deleteLine($_GET['line']);
  17.  
  18. echo $plik->deletedMessage();
  19. }
  20. ?>


pliku class.deleteLine.php nie zmieniasz... chyba wiesz jak to działa.... wyświetlanie linii podobne do shizo ale usuwanie inne (IMG:http://forum.php.pl/style_emoticons/default/smile.gif) łatwiejsze... pamiętaj, że musisz zaincludować plik class.deleteLine.php

dobra ja spadam... nara!
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 25.08.2025 - 04:52