I am looking for a function that suits the following situation.
What the script does:
It retrieves the server.log from a minecraft server, and breaks it into sections from user chats, to server notifications etc.
I have an array containing the users information, it is set by another file called users.yml
and it is converted to an array like so
$userconfig = array(
'TruDan' => array(
'prefix' => '&3',
'suffix' => '&e',
),
'TruGaming' => array(
'prefix' => '&c',
'suffix' => '&f',
),
'PancakeMiner' => array(
'prefix' => '&c',
'suffix' => '&f',
),
'Teddybear952' => array(
'prefix' => '&b',
'suffix' => '&f',
),
);
What i want to do, is search the $line from server.log (it loops through lines) for a username above (array key) and return the array. so i can then parse $ret[‘prefix’] and $ret[‘suffix’]
mc.php (the file) http://pastebin.com/9geyfuup
server.log (partial, the actual thing is 12,000 lines long, so i took a few lines from it) http://pastebin.com/DKz8YfgK
If you’re using preg_match() to search each line for a username, make sure you first sort the list of usernames in reverse order using
rsort():If you search a line for the pattern
"/TruDan|TruDan123/"the search will match a line containing"TruDan123"to the shorter version"TruDan"because it was specified first in the pattern. Sorting the user list in reverse order ensures that the pattern will be"/TruDan123|TruDan/"and so give preference to the longer match.