Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5987885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T22:52:47+00:00 2026-05-22T22:52:47+00:00

I am looking for a function that suits the following situation. What the script

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T22:52:47+00:00Added an answer on May 22, 2026 at 10:52 pm

    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():

    $users = array_map('preg_quote', array_keys($userconfig));
    rsort($users);
    $pattern = '/' . implode('|', $users); . '/';
    if preg_match($pattern, $line, $matches) {
        return matches[0];
    }
    else {
        return array();
    }
    

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to implement a function that retrieves a single frame from an input
I am looking for a function that will partition a list into fixed size
I'me looking for a function that would receive a time and would round it
Original Question I am looking for a function that attempts to quantify how distant
I am not that familiar with Javascript, and am looking for the function that
For my jq driven form I am looking for a function that clears my
I am looking to create a function that could create a fade-in/fade-out function on
Looking for a nifty helper function/method for grepping through all defined tables, columns, stored
I'm looking for a method (or function) to strip out the example.ext part of
I'm looking for a PHP library/function/class which can create Identicon s.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.