Working on a small project.
I'm new to PHP and I am trying to write a log parser.
The logs currently look like this:
3:40 say: Colonel Mustard: console 3:43 say: Colonel Mustard: it says 3:47 say: Colonel Mustard: console: what? 4:02 say: Colonel Mustard: k 4:07 say: Colonel Mustard: 4:07 1:35 say: ^#[RO^3DF]^!Taomech^!: need to se if sd works
And my current code is:
<?PHP $game_file = fopen("c:/game.log", "r"); while (!feof($game_file)) { $line_of_text = fgets($game_file); //gets time, works preg_match("/([0-9]+)\<img src='http://www.geekstogo.com/forum/public/style_emoticons/<#EMO_DIR#>/sad.gif' class='bbc_emoticon' alt=':D' />[0-9]+)/", $line_of_text, $time_matches); //matchs name, but onyl works if name is "name name" not "name". preg_match("/say\:\s([a-z]+)\s([a-z]+)\:/i", $line_of_text, $name_matches_space); preg_match("/say\:\s([a-z]+)\:/i", $line_of_text, $name_matches_nospace); echo "Time is : {$time_matches[0]} Name is : {$name_matches_space[1]} {$name_matches_space[2]} {$name_matches_nospace[1]}. . . . . . . Original is : {$line_of_text} . <BR>"; } fclose($game_file); ?>
Currently the script works, but is there a way to make it smaller?
Also, the actual logs I will be parsing are like the last one in the example, with the ^! etc. Is there a way to perform the match, while still keeping the ^! etc?
Thanks,
Taomech
Edited by Taomech, 20 September 2010 - 04:07 AM.