Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP]Odczyt daty w pliku txt.
globalinfo
post
Post #1





Grupa: Zarejestrowani
Postów: 55
Pomógł: 0
Dołączył: 8.10.2006

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


Witam,

Nie mogę sobie dać rady z odczytaniem daty z plku txt.

Mam taki kod

  1. $stringFromFile = fread($stateFile,filesize(myStateName));
  2. fclose($stateFile);
  3. $pos = strpos($stringFromFile, " ");
  4. echo "<br>";
  5. echo $pos;
  6. echo $stringFromFile;
  7. echo "<br>";
  8. echo substr($stringFromFile, 0, $pos);
  9. echo "<br>";
  10. $lastTime = date("Y-m-d H:i:s",substr($stringFromFile, 0, $pos));
  11. $lastReset = substr($stringFromFile, $pos+3);
  12. if (substr($stringFromFile, $pos+1,1)=="0")
  13. $lastState = "Off";
  14. else
  15. $lastState = "On";
  16. echo "Last auto-contact from the water heater was on ". $lastTime. " and the status was ". $lastState. " (Reset was ".$lastReset." Minutes ago)";


Niestety podczas wykonania otrzymuję błąd.
Poniżej wynik wyświetlony na stronie.
Cytat
13
1488113398 23 56 67
1488113398

Warning: date() expects parameter 2 to be long, string given in /....................php on line 240
Last auto-contact from the water heater was on and the status was On (Reset was 56 67 Minutes ago)

Wartość jaka wpisana jest w pliku
Cytat
1488113398 23 56 67


Nie bardzo wiem jak to ugryźć (IMG:style_emoticons/default/sciana.gif)

Ten post edytował globalinfo 26.02.2017, 14:37:21
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
rafkon1990
post
Post #2





Grupa: Zarejestrowani
Postów: 37
Pomógł: 9
Dołączył: 14.09.2016
Skąd: Śląskie

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


  1.  
  2. $stringFromFile = "1488113398 23 56 67";
  3. $exploded = explode(' ', $stringFromFile);
  4. $lastTime = date("Y-m-d H:i:s",$exploded[0]);
  5. unset($exploded[0]);
  6. $last = implode(' ',$exploded);
  7. if ($last[1]=="0")
  8. $lastState = "Off";
  9. else
  10. $lastState = "On";
  11. echo "Last auto-contact from the water heater was on ". $lastTime. " and the status was ". $lastState. " (Reset was ".$last." Minutes ago)";
  12.  
  13.  


Last auto-contact from the water heater was on 2017-02-26 07:49:58 and the status was On (Reset was 23 56 67 Minutes ago)
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: 3.10.2025 - 22:44