Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [PHP] Pobieranie zawartości
lanceq
post 8.07.2012, 12:28:38
Post #1





Grupa: Zarejestrowani
Postów: 36
Pomógł: 0
Dołączył: 3.07.2012

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


Witam, chciałbym zdalnie pobrać zawartość pewnego pliku na zewnętrznym serwerze.
Plik z którego chce pobierać znajduje się na: http://ot.lanceq.pl/config/serverstatus

Zawartość tego pliku wygląda tak:

serverStatus_checkInterval = "303"
serverStatus_lastCheck = "1341746105"
serverStatus_online = "1"
serverStatus_players = "0"
serverStatus_playersMax = "1000"
serverStatus_uptime = "0h 18m"
serverStatus_monsters = "724"

(te wartości się zmieniają)


Chciałbym aby na zdalnym serwerze był wyświetlany wynik dla: serverStatus_players, serverStatus_playersMax, serverStatus_uptime i serverStatus_monsters oraz dla serverStatus_online ale w _online chciałbym że gdy == 1 to żeby wypisywało online a jak _online == 0 to żeby wypisywało offline.

Pozdrawiam.

Ten post edytował lanceq 8.07.2012, 12:29:23
Go to the top of the page
+Quote Post
konrados
post 8.07.2012, 12:40:12
Post #2





Grupa: Zarejestrowani
Postów: 623
Pomógł: 79
Dołączył: 16.01.2008

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


get_file_contents oraz parse_ini_string
Go to the top of the page
+Quote Post
lanceq
post 8.07.2012, 13:53:07
Post #3





Grupa: Zarejestrowani
Postów: 36
Pomógł: 0
Dołączył: 3.07.2012

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


  1. <?php
  2. $wynik = file_get_contents('http://ot.lanceq.pl/config/serverstatus');
  3. echo $wynik;
  4. ?>


Zrobiłem tak i wyświetla to tak

serverStatus_checkInterval = "303" serverStatus_lastCheck = "1341750803" serverStatus_online = "1" serverStatus_players = "0" serverStatus_playersMax = "1000" serverStatus_uptime = "1h 37m" serverStatus_monsters = "724"

Za bardzo nie wiem jak wykorzystać parse_ini_string w tym.
Chciałbym żeby to wyświetlało się tak:

Online/Offline: serverStatus_online
Uptime: serverStatus_uptime
Ilość graczy: serverStatus_players / serverStatus_playersMax
Ilość potworów: serverStatus_monsters

Ten post edytował lanceq 8.07.2012, 13:53:58
Go to the top of the page
+Quote Post
konrados
post 8.07.2012, 14:28:03
Post #4





Grupa: Zarejestrowani
Postów: 623
Pomógł: 79
Dołączył: 16.01.2008

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


Że co, nie ma tam newlines (enterów)? W takim razie spróbuj z explode:
  1. $array = explode(" = ", $wynik);
  2. var_dump($array);//to tylko po to byś zobaczył jak to wygląda
Go to the top of the page
+Quote Post
lanceq
post 8.07.2012, 14:32:45
Post #5





Grupa: Zarejestrowani
Postów: 36
Pomógł: 0
Dołączył: 3.07.2012

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


  1. <?php
  2. $wynik = file_get_contents('http://ot.lanceq.pl/config/serverstatus');
  3. $array = explode(" = ", $wynik);
  4. var_dump($array);//to tylko po to byś zobaczył jak to wygląda
  5. ?>


I wyświetla się to tak

array(8) { [0]=> string(26) "serverStatus_checkInterval" [1]=> string(29) ""303" serverStatus_lastCheck" [2]=> string(33) ""1341753794" serverStatus_online" [3]=> string(25) ""1" serverStatus_players" [4]=> string(28) ""0" serverStatus_playersMax" [5]=> string(27) ""1000" serverStatus_uptime" [6]=> string(31) ""2h 27m" serverStatus_monsters" [7]=> string(7) ""724" " }


Trochę nie tak jak chciałem.

Ten post edytował lanceq 8.07.2012, 14:33:01
Go to the top of the page
+Quote Post
konrados
post 8.07.2012, 14:40:12
Post #6





Grupa: Zarejestrowani
Postów: 623
Pomógł: 79
Dołączył: 16.01.2008

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


No to są podstawy podstaw... teraz możesz np. napisać tak:

  1. echo 'serverStatus_online:<b>'.$array[3].'</b>';


Jest 3 bo na 3-ciej pozycji masz wartość dla 'serverStatus_online' co widzisz dzięki var_dump

update:a nie, czekaj, coś jest nie tak z tym arrayiem, chwila...

Ten post edytował konrados 8.07.2012, 14:48:48
Go to the top of the page
+Quote Post
lanceq
post 8.07.2012, 14:58:20
Post #7





Grupa: Zarejestrowani
Postów: 36
Pomógł: 0
Dołączył: 3.07.2012

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


Dodałem to:

  1. echo '<br>Ilosc graczy:<b>'.$array[4].'</b> / '.$array[5].'';

I wyświetla:

Ilosc graczy:"0" serverStatus_playersMax / "1000" serverStatus_uptime

Chciałbym żeby wyświetlało

Ilosc graczy: 0/1000


Bez tych dodatków.

Ten post edytował lanceq 8.07.2012, 14:58:43
Go to the top of the page
+Quote Post
konrados
post 8.07.2012, 15:04:25
Post #8





Grupa: Zarejestrowani
Postów: 623
Pomógł: 79
Dołączył: 16.01.2008

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


Zrób tak:
  1. //$wynik =str_replace('" ',"\"\r\n",$wynik);//to tylko jeśli naprawdę nie ma enterów w tym pliku. Ale widzę, że są.
  2. $array=parse_ini_string ($wynik);
  3. var_dump($array);
  4. echo 'serverStatus_online:<b>'.$array['serverStatus_online'].'</b>';


Ten post edytował konrados 8.07.2012, 15:05:35
Go to the top of the page
+Quote Post
lanceq
post 8.07.2012, 15:55:11
Post #9





Grupa: Zarejestrowani
Postów: 36
Pomógł: 0
Dołączył: 3.07.2012

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


Dzięki wielkie już to ogarnąłem.
Go to the top of the page
+Quote Post

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

 



RSS Wersja Lo-Fi Aktualny czas: 28.05.2024 - 01:58