Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Operacje na strignach?
EastWest
post 23.09.2013, 17:23:37
Post #1





Grupa: Zarejestrowani
Postów: 35
Pomógł: 0
Dołączył: 1.08.2013

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


Hej!
Mam problem C:
Mam takie coś:
  1. 17:27:36 [INFO] [Skript] Enabling Skript v2.0 beta 10
  2.  
  3. 17:27:38 [INFO] [JSONAPI] Chat cannot be loaded because it depends on a plugin that is not installed: 'Vault'
  4.  
  5. 17:27:38 [INFO] [JSONAPI] Dynmap cannot be loaded because it depends on a plugin that is not installed: 'dynmap'


chcę jednak otrzymać:

  1. <strong>17:27:36 [INFO] [Skript]</strong> Enabling Skript v2.0 beta 10
  2.  
  3. <strong>17:27:38 [INFO] [JSONAPI]</strong> Chat cannot be loaded because it depends on a plugin that is not installed: 'Vault'
  4.  
  5. <strong>17:27:38 [INFO] [JSONAPI]</strong> Dynmap cannot be loaded because it depends on a plugin that is not installed: 'dynmap'


Da się to jakoś zrobić? Jak widać długość stringa jest różna. Pomoże ktoś? sad.gif
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
Crozin
post 23.09.2013, 18:21:16
Post #2





Grupa: Zarejestrowani
Postów: 6 476
Pomógł: 1306
Dołączył: 6.08.2006
Skąd: Kraków

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


Przy pomocy wyrażeń regularnych możesz odczytać poszczególne elementy każdej z linii:
Kod
#(?P<time>\d{2}:\d{2}:\d{2})\s+\[(?P<type>\w+)\]\s+\[(?P<source>\w+)\]\s+(?P<message>.*)#
Mając już poszczególne elementy wiadomości możesz ją sobie powtórnie sformatować w dowolny sposób.
Go to the top of the page
+Quote Post
EastWest
post 23.09.2013, 18:28:35
Post #3





Grupa: Zarejestrowani
Postów: 35
Pomógł: 0
Dołączył: 1.08.2013

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


Jak zastosować to w praktyce? W php świeżak jestem :3
Go to the top of the page
+Quote Post
Crozin
post 23.09.2013, 18:35:58
Post #4





Grupa: Zarejestrowani
Postów: 6 476
Pomógł: 1306
Dołączył: 6.08.2006
Skąd: Kraków

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


file + foreach - by odczytać każdą linię z pliku
preg_match - by wydobyć informacje z poszczególnych linii
Go to the top of the page
+Quote Post
EastWest
post 23.09.2013, 19:27:28
Post #5





Grupa: Zarejestrowani
Postów: 35
Pomógł: 0
Dołączył: 1.08.2013

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


  1. Array
  2. (
  3. [result] => success
  4. [source] => getLatestConsoleLogsWithLimit
  5. [success] => Array
  6. (
  7. [0] => Array
  8. (
  9. [time] => 1379960346
  10. [line] => 2013-09-23 20:19:06 [INFO] [JSONAPI] [API Call] 127.0.0.1: method=getLatestConsoleLogsWithLimit?args=[10]
  11.  
  12. )
  13.  
  14. [1] => Array
  15. (
  16. [time] => 1379960357
  17. [line] => 2013-09-23 20:19:17 [INFO] [JSONAPI] [API Call] 127.0.0.1: method=getLatestConsoleLogsWithLimit?args=[10]
  18.  
  19. )
  20.  
  21. [2] => Array
  22. (
  23. [time] => 1379960423
  24. [line] => 2013-09-23 20:20:23 [INFO] [JSONAPI] [API Call] 127.0.0.1: method=getLatestConsoleLogsWithLimit?args=[10]
  25.  
  26. )
  27.  
  28. [3] => Array
  29. (
  30. [time] => 1379960475
  31. [line] => 2013-09-23 20:21:15 [INFO] [JSONAPI] [API Call] 127.0.0.1: method=getLatestConsoleLogsWithLimit?args=[10]
  32.  
  33. )
  34.  
  35. [4] => Array
  36. (
  37. [time] => 1379960542
  38. [line] => 2013-09-23 20:22:22 [INFO] [JSONAPI] [API Call] 127.0.0.1: method=getLatestConsoleLogsWithLimit?args=[10]
  39.  
  40. )
  41.  
  42. [5] => Array
  43. (
  44. [time] => 1379960603
  45. [line] => 2013-09-23 20:23:23 [INFO] [JSONAPI] [API Call] 127.0.0.1: method=getLatestConsoleLogsWithLimit?args=[10]
  46.  
  47. )
  48.  
  49. [6] => Array
  50. (
  51. [time] => 1379960633
  52. [line] => 2013-09-23 20:23:53 [INFO] [JSONAPI] [API Call] 127.0.0.1: method=getLatestConsoleLogsWithLimit?args=[10]
  53.  
  54. )
  55.  
  56. [7] => Array
  57. (
  58. [time] => 1379960651
  59. [line] => 2013-09-23 20:24:11 [INFO] EastWestFM[/127.0.0.1:60957] logged in with entity id 104641 at ([p4] -2.547157902657159, 130.30604331375685, -198.44224001524643)
  60.  
  61. )
  62.  
  63. [8] => Array
  64. (
  65. [time] => 1379960653
  66. [line] => 2013-09-23 20:24:13 [INFO] EastWestFM issued server command: /help
  67.  
  68. )
  69.  
  70. [9] => Array
  71. (
  72. [time] => 1379960656
  73. [line] => 2013-09-23 20:24:16 [INFO] [JSONAPI] [API Call] 127.0.0.1: method=getLatestConsoleLogsWithLimit?args=[10]
  74.  
  75. )
  76.  
  77. )
  78.  
  79. )


Taką mam tablicę

Taki kod:

  1. $pattern = '#(?P<time>\d{2}:\d{2}:\d{2})\s+\[(?P<type>\w+)\]\s+\[(?P<source>\w+)\]\s+(?P<message>.*)#';
  2. foreach ($tablica as $linia) {
  3. foreach ($linia as $linia1) {
  4. foreach ($linia1 as $linia2) {
  5. $l = substr($linia2, 10);
  6. preg_match($pattern, $l, $matches);
  7. echo "<strong>".$matches['time']." >> [".$matches['type']."] [".$matches['source']."]: </strong>".$matches['message']."<br />";
  8. }
  9. }
  10. }
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: 24.06.2025 - 13:55