Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] tabela w pliku, okresowa tabela z danymi
noche
post
Post #1





Grupa: Zarejestrowani
Postów: 46
Pomógł: 0
Dołączył: 20.02.2015

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


witam, poszukuje rozwiązań do stworzenia tabeli w pliku tymczasowym
chodzi mi o to aby otworzyć plik który będzie powstawał raz dziennie i przechowywał tabele
problem w tym że będzie około 5 kolumn, 1000 wierszy i musi to być w pliku

proszę o podpowiedzi, sugestie jak można ugryźć ten temat

pozdrawiam
Go to the top of the page
+Quote Post
Tomplus
post
Post #2





Grupa: Zarejestrowani
Postów: 1 879
Pomógł: 230
Dołączył: 20.03.2005
Skąd: Będzin

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


możesz tablicę zapisać w takich postaciach i jeszcze wielu innych

  1. $var[1] = json_encode($array); //koduje jako plik JSON
  2. $var[2] = serialize($array); //strumieniowanie do stringu
  3. $var[3] = own_function_array_to_xml($array); // jako XML
  4. file_put_contents('file1.json',$var[1]);
  5. file_put_contents('file2.csv',$var[2]);
  6. file_put_contents('file3.xml',$var[3]);


a dekodujesz pobierając plik np.

  1. $array = json_decode(file_get_contents('file1.json'), true);
  2. $object = json_decode(file_get_contents('file1.json'));
Go to the top of the page
+Quote Post
noche
post
Post #3





Grupa: Zarejestrowani
Postów: 46
Pomógł: 0
Dołączył: 20.02.2015

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


Dzięki wielkie bardzo mi się spodobała opcja serialize (IMG:style_emoticons/default/smile.gif)

Kod
$file = 'test.txt';
$array[] = array ( 'value1' => 11 , 'value2' => 23232 );
$array[] = array ( 'value1' => 12 , 'value2' => 23232 );
$array[] = array ( 'value1' => 13 , 'value2' => 23232 );

$serializedArray= serialize($array); #serializacja tablicy
//$unserializedArray= unserialize($serializedArray); #deserializaja

file_put_contents( $file, $serializedArray );
$file_get = file_get_contents( $file, true );

$unserializedArray = unserialize( $file_get ); #deserializaja

print_r( $unserializedArray );
Go to the top of the page
+Quote Post

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: 22.08.2025 - 20:20