Autor Beitrag
Martok
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Sa 01.09.07 19:17 
Hi Leute!

Ich möchte per PHP eine Datei (wens interessiert: SA:MP Ban-Definitions-Datei) parsen und in eine Datenbank einlesen.
Die Datei besteht aus Zeilen in diesem Format:
ausblenden Quelltext
1:
IP [01/09/07 | 01:17:39] PLAYERNAME - INFOTEXT					


Diese möchte ich ein eine DB mit den Feldern IP, UPDATE, NAME zerlegen. Den Infotext brauch ich nicht.
Die Datei wird per HTTP-Upload an ein PHP-Script übertragen.

Meine Frage jetzt: was brauche ich dafür für Funktionen? Mit Dateiverarbeitung unter PHP hab ich nie was gemacht, also hab ich da so gar keine Ahnung... Irgendwie muss ich die Datei zeilenweise kriegen... danach die paar RegEx drüberschicken ist nicht so das Problem.

Danke schonmal,
Martok

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
TProgger
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 148

XP
D6, D2007 prof
BeitragVerfasst: Sa 01.09.07 19:57 
Hi,
das lässt sich relativ einfach realisieren. Mit der Function file() geht das.
Zitat:
Zitat:

Die Funktion file() ist identisch mit readfile(), außer dass die eingelesene Datei als Array zurückgegeben wird. Jedes Feld des Arrays korrespondiert mit einer Zeile der Datei. Der Zeilenumbruch bleibt erhalten. Im Fehlerfall gibt file() FALSE zurück.

Allerdings muss man sich schon etwas mit php uns MySQL befassen, denn man müsste übe CREATTABLE erst mal eine entsprechende Table anlegen.
Weiterführende Links www.php-homepage.de/manual/ und
de3.php.net/manual/de/

Gruß
Martok Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 3661
Erhaltene Danke: 604

Win 8.1, Win 10 x64
Pascal: Lazarus Snapshot, Delphi 7,2007; PHP, JS: WebStorm
BeitragVerfasst: Sa 01.09.07 20:19 
So einfach ist das? Cool ;)

Und den Rest kann ich ja... auch wenn ich deinen ersten Link noch nicht kannte^^

EDIT: so, alles fertig. War ja richtig einfach ;)

_________________
"The phoenix's price isn't inevitable. It's not part of some deep balance built into the universe. It's just the parts of the game where you haven't figured out yet how to cheat."
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: So 02.09.07 17:23 
ausblenden Quelltext
1:
2:
3:
4:
5:
6:
preg_match_all('/^(\\d+\\.\\d+\\.\\d+\\.\\d+)\\s+\\[(.+?)\\]\\s+(\\w+)\\s+\\-\\s+(.+)$/im', $subject, $result, PREG_SET_ORDER);
for ($matchi = 0; $matchi < count($result); $matchi++) {
  for ($backrefi = 0; $backrefi < count($result[$matchi]); $backrefi++) {
    // $result[$matchi][$backrefi];
  } 
}


Dann nur noch in die DB eintragen ;-)

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.