仅输出与关键字匹配的行

时间:2017-02-15 07:37:53

标签: regex string file search keyword

我尝试仅输出与关键字匹配的表行中的那些,但不起作用。我正在尝试使用strpos,substr和其他功能。我的代码看起来像这样。有人有想法,如何解决它并正确调整该功能?

 <?php

    $start_date = strtotime($_POST['start']);
    $end_date = strtotime($_POST['end']);

    settype($start_date, "integ`enter code here`er");  
    settype($end_date, "integer");

    $total = 0;


        if (isset($_POST["start"]) && !empty($_POST["end"])) {

            $files = glob('arch/*.log.*');   

>scan files



foreach($files as $failas)
            {   
                $file_mod_time = filemtime($failas);

                            if (($start_date<$file_mod_time) && ($end_date>$file_mod_time)) //looking for specific date
                        {   

                $file = @fopen($failas, "r") or die("Cannot open file!\n");  
                while ($filePart = fread($file, 4146)) { 
                    preg_match_all('/(?>--\w{8}-A--).*?(?=(--\w{8}-A--)|\Z)/s', $filePart, $blockMatch, PREG_SET_ORDER);  


                    foreach ($blockMatch as $singleBlockMatch) {
                        if (isset($singleBlockMatch[0])) {
                            preg_match_all('/.*?--\w{8}-A--\n(.*?)\s\w*?\s(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}).*?POST (\S*?) HTTP.*?--\w{8}-C--\s(.*?\s)/s', $singleBlockMatch[0], $match, PREG_SET_ORDER); // reads a blocks


                             /* var_dump($match); */    
                            /* if (strpos($singleBlockMatch[0],$_POST['search'])===($match)) {*/ 
                            foreach ($match as $pos) {


                        $search = $_POST['search'];         
                        $pos = strpos($singleBlockMatch[0], $search);             //tries take specific rows, matching keyword

                        $wert = substr($singleBlockMatch[0],$pos);  
                            }   ?>  
                                 <tr>
                    <td><?php echo $total++; ?></td>
                    <td> <?php echo $wert[1]; ?></td>
                    <td> <?php echo $wert[2]; ?></td>
                    <td> <?php echo $wert[3]; ?></td>
                    <td> <?php echo $wert[4]; ?></td>
                    <?php                                  



        }
                        }
                    }
                }


            }
            }
        else {
                    echo "Fill a fields";
                }   
     ?>

enter image description here

0 个答案:

没有答案