Yogiz Posted March 4, 2008 Share Posted March 4, 2008 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 Quote Link to comment Share on other sites More sharing options...
discomatt Posted March 4, 2008 Share Posted March 4, 2008 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. Quote Link to comment Share on other sites More sharing options...
Yogiz Posted March 4, 2008 Author Share Posted March 4, 2008 Could someone give me some more guidance on how to get this log file into a HTML table? Thanks in advance Yogiz Quote Link to comment Share on other sites More sharing options...
craygo Posted March 4, 2008 Share Posted March 4, 2008 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 Quote Link to comment Share on other sites More sharing options...
Yogiz Posted March 4, 2008 Author Share Posted March 4, 2008 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 Quote Link to comment Share on other sites More sharing options...
Yogiz Posted March 6, 2008 Author Share Posted March 6, 2008 Could someone please provide me with some code on how to get this data from the file into an array. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.