Text parsing, matching text

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Text parsing, matching text

Post 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
Last edited by Benjamin on Sun Apr 25, 2010 11:43 pm, edited 1 time in total.
Reason: Changed CODE to SYNTAX tags..
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Text parsing, matching text

Post by requinix »

Help with what? Writing your code for you?
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Re: Text parsing, matching text

Post by JKM »

... or helping along. :)
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Re: Text parsing, matching text

Post 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!
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Re: Text parsing, matching text

Post 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.
Post Reply