Page 1 of 1

Text parsing, matching text

Posted: Sun Apr 25, 2010 6:28 pm
by JKM

Code: Select all

/*

    form fields:
        `log_dir`    = machine1, machine2 etc
        `log_month`    = 01, 02 etc
        `log_option`    = checked/unchecked
        `log_string1`    = custom search string 1
        `log_string2`    = custom search string 2
        
*/
            
// list files
    $dir = '/home/user/public_html/logs/';
    if(!$_POST['log_submit']) {
        $log_dir    = 'machine1';
        $log_month    = date('m');
        $log_option    = false;
        $log_string1    = false;
        $log_string2    = false;
    } else {
        $log_dir    = $_POST['log_dir'];
        $log_month    = $_POST['log_month'];
        if($_POST['log_option']) {
            $log_option = 'error';
        } else {
            $log_option = false;
        }
        if(!empty($_POST['log_string1'])) {
            $log_string1 = $_POST['log_string1'];
        } else {
            $log_string1 = false;
        }
        if(!empty($_POST['log_string2'])) {
            $log_string2 = $_POST['log_string2'];
        } else {
            $log_string2 = false;
        }
    }    

    /*
        * parse through all files from $dir.$log_dir that matches 'log_'.$log_month.'*.log
        * (the logs are separated into log_<month>0001.log, log_<month>0002.log and so on)
        * if(!$log_string1 || !$_POST['log_submit'])
        *         { list all files that starts with 'log_'.$log_month }
        * elseif($_POST['log_submit'] && $log_string1 != false)
        *         if(number_of_files != 0)
        *             { list all files that matches the criterias ($log_option, $log_string1, $log_string2) that isn't falsed }
        *         else
        *             { echo 'No matching logs'; }
    */

// view log file
    $badwords = array('word1', 'word2', 'word3');
    if($_GET['view'] === 'true' && isset($_GET['month']) && isset($_GET['string1'])) {
        /*
            * show lines that matches the criterias:
            * include word $_GET['string1']
            * if($_GET['option'] == 1)
            *         { include word 'error' }
            * if(isset($_GET['string2']))
            *         { include word $_GET['string2'] }
            * exlude all lines that contains $badwords
            * FROM all files from $dir.$log_dir that matches 'log_'.$log_month.'*.log
            * if($matches != 0)
            *         { echo 'No matches.' }
        */
    } else {
        echo 'error - select a file.';
    }  
Thanks for any help! <3

Re: Text parsing, matching text

Posted: Sun Apr 25, 2010 6:43 pm
by requinix
Help with what? Writing your code for you?

Re: Text parsing, matching text

Posted: Sun Apr 25, 2010 7:04 pm
by JKM
... or helping along. :)

Re: Text parsing, matching text

Posted: Sun Apr 25, 2010 10:34 pm
by Luke
LOL do you actually expect anybody to help you with such a vague explanation of what you need? Would YOU help you if you were us? Give us more information. What are you trying to do? What exactly do you need help with? Don't just post a giant php script and expect us to sift through it and figure out what you're talking about. Explain, dude!

Re: Text parsing, matching text

Posted: Mon Apr 26, 2010 9:00 pm
by JKM
Luke wrote:LOL do you actually expect anybody to help you with such a vague explanation of what you need? Would YOU help you if you were us? Give us more information. What are you trying to do? What exactly do you need help with? Don't just post a giant php script and expect us to sift through it and figure out what you're talking about. Explain, dude!
LOL LOL! It's ~20 lines with comments that explained my problem.

The main issue, is how to match strings that the users is searching for. The strings could be like this (and they require regex, right?):
USER:12345
_'help'_
He/\y

Also, I'm having a badwords array:
$badwords = array('word1', 'word2', 'word3');
and I'm wondering how I can check if the line contains any of these words.