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
https://forums.phpfreaks.com/topic/94277-question/
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
https://forums.phpfreaks.com/topic/94277-question/#findComment-482903
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
https://forums.phpfreaks.com/topic/94277-question/#findComment-483200
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
https://forums.phpfreaks.com/topic/94277-question/#findComment-483204
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.