Jump to content

Question


Yogiz

Recommended Posts

Hi there.

 

How can I extract data from a log file which consists of 10 columns and has the following format;

                             

                "1193188568.265    187 10.164.117.2 TCP_MISS/200 1983 GET www.example.com - DIRECT/208.69.34.231 text/html"

 

What would be the best way of outputting this into HTML format so that it can be manipulated etc

 

Should I insert all this into a database first and then work from that?

 

Thanks in advance.

 

Yogiz

 

Link to comment
Share on other sites

Unless you can dump the log files directly into the database, it won't help much.

 

The easier method for this will be to use a combination of file functions (fopen, fread)

http://php.net/manual/en/ref.filesystem.php

 

And the explode function

http://php.net/manual/en/function.explode.php

 

This will split all of the data into an array, which you can then manipulate with php fairly easily.

Link to comment
Share on other sites

can use fgetcsv but you would need to know what the delimiter is. Look like it may be a space in the above example

 

<?php
echo "<table>\n";
$handle = fopen("test.csv", "r");
while (($data = fgetcsv($handle, 1000, " ")) !== FALSE) {
    echo "<tr>\n";
    $num = count($data);
    for ($c=0; $c < $num; $c++) {
        echo "<td>" . $data[$c] . "</td>\n";
    }
    echo "</tr>\n";
}
echo "</table>\n";
fclose($handle);
?>

 

Ray

 

Link to comment
Share on other sites

Yes there are spaces between each column.

 

Column No.            1              2            3                4                  5      6        7    8              9                        10

                1193188579.500 | 63 | 10.164.117.2 | TCP_MISS/200 | 902 | GET | www |-| DIRECT/212.187.229.42 | text/html

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.