473,385 Members | 1,523 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

explode?

AJ
Hi All

I've just had anti virus installed on my server. There is a log file that
shows all the viruses that have been trapped. There are lots of different
lines in the log file but the ones I'm interested in look like this:

/var/amavis/amavis-012184/parts/part-00002: Worm.SomeFool.B-petite FOUND

What I want to write a little PHP script that will display the results on a
web page. So, my first task will be to extract only the lines that begine
with /var/amavis, or even only those that end with FOUND.

Then I want to take all the characters between the : and the F and display
those.

It would be nice if I could display a count of how many viruses had been
caught so far.

Lastly, I really only want to display, say, 30 lines at a time.

Then I pop a refresh on the page and we can hopefully see the viruses as
they come in. It's just so I can show customers how clever this is.

I'm going to start digging myself through the PHP manual but if anyone could
offer any guidance I'd be most grateful. I think it might be explode that I
want to use, but I'm not sure. Nor am I sure how to select only the
relevant lines and just display the last 30.

Best

Andy
Jul 17 '05 #1
1 1636
AJ wrote:
I've just had anti virus installed on my server. There is a log file that
shows all the viruses that have been trapped. There are lots of different
lines in the log file but the ones I'm interested in look like this:

/var/amavis/amavis-012184/parts/part-00002: Worm.SomeFool.B-petite FOUND

What I want to write a little PHP script that will display the results on a
web page. So, my first task will be to extract only the lines that begine
with /var/amavis, or even only those that end with FOUND.
Use preg_match_all()
http://www.php.net/preg_match_all

Remember the correct modifier for multiline mode!
Then I want to take all the characters between the : and the F and display
those.
that is also part of preg_match_all()
It would be nice if I could display a count of how many viruses had been
caught so far.
Save the count in a array with virus names as indexes, eg:
$array['Worm.SomeFool.B-petite'] = 18;
Lastly, I really only want to display, say, 30 lines at a time.
Best is a for loop
I'm going to start digging myself through the PHP manual but if anyone could
offer any guidance I'd be most grateful. I think it might be explode that I
want to use, but I'm not sure. Nor am I sure how to select only the
relevant lines and just display the last 30.

SPOILER FOLLOWS -- try to make the script on your own

....



....



....



....



....



....



....





<?php
// get data
# read from file instead
$data = "
/var/amavis/amavis-012184/parts/part-00002: Worm.SomeFool.B-petite FOUND
/amavis/amavis-012184/parts/part-00002: Worm.SomeFool.A-petite FOUND
/amavis/amavis-012184/parts/part-00002: Worm.SomeFool.C-petite FOUND
/var/amavis/amavis-012184/parts/part-00002: Worm.SomeFool.C-petite FOUND
/var/amavis/amavis-012184/parts/part-00002: Worm.SomeFool.B-petite FOUND
/var/amavis/amavis-012184/parts/part-00002: Worm.SomeFool.B-petite DELETED
/var/amavis/amavis-012184/parts/part-00002: Worm.SomeFool.A-petite DELETED
/var/amavis/amavis-012184/parts/part-00002: Worm.SomeFool.C-petite FOUND
/var/amavis/amavis-012184/parts/part-00002: Worm.SomeFool.B-petite FOUND
/var/amavis/amavis-012184/parts/part-00002: Worm.SomeFool.A-petite FOUND
/var/amavis/amavis-012184/parts/part-00002: Worm.SomeFool.A-petite FOUND
/var/amavis/amavis-012184/parts/part-00002: Worm.SomeFool.A-petite FOUND
/var/amavis/amavis-012184/parts/part-00002: Worm.SomeFool.B-petite FOUND
/var/amavis/amavis-012184/parts/part-00002: Worm.SomeFool.B-petite FOUND
";
# for example:
#$data = file_get_contents('amavis.log');

// find all lines matching specification
preg_match_all('@^/var/amavis/[^:]+: (.*) FOUND$@m', $data, $matches);

// populate result array
foreach ($matches[1] as $virus_name) {
if (!isset($viruses[$virus_name])) $viruses[$virus_name] = 0;
// HACK!! :: decrement for asort() to work ascendingly
$viruses[$virus_name]--;
}

asort($viruses);
foreach ($viruses as $v=>$q) {
# you might want to make this nicer HTML :)
# I tested with the command-line PHP
// HACK!! :: remember to reverse the sign
echo $v, ': ', -$q, "\n";
}
?>
Result with that constant data:
Worm.SomeFool.B-petite: 5
Worm.SomeFool.A-petite: 3
Worm.SomeFool.C-petite: 2
--
--= my mail box only accepts =--
--= Content-Type: text/plain =--
--= Size below 10001 bytes =--
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Rob Gudgeon | last post by:
Hi Is it possible to explode a string into an array using more than one separator? I have database records that contain several values, mostly split by semi-colons but some older records are...
6
by: William Krick | last post by:
I have a string containing concatenated ascii "records" that are each terminated by '\n'. For testing purposes, I construct sample data like this... $mystring =...
4
by: Richard Lawrence | last post by:
Hi there, I'm having a problem with PHP which I'm not sure how to best solve. Here is the code: $fp = fopen("comments.txt", "r"); while(!feof($fp)) { $line = fgets($fp, 1024); list($key,...
12
by: frizzle | last post by:
Hi there, i have a site with fake folders & files. htaccess rewrites everything to index.php?vars now in index.php i decide what file to include with a switch/case statement. to define where...
5
by: FFMG | last post by:
Hi, I need the php equivalent of explode in one of my app. I read a very big file and "explode" each line to fill a structure. The reading of the file, 19Mb, (I will also need to streamline...
0
by: k04jg02 | last post by:
Python has a nifty operator that will take a container and pass its elements as function parameters. In Python you can make a list like so: x = Then you can say: f(*x)
4
by: Davide | last post by:
Hi All, I'm trying to use explode to separate the result of a textual file, but it explode me only the first row. the foo.txt is pippo pluto pluto pippo pippo pippo .... I use this script...
8
by: Jack | last post by:
I would like to Explode a string into an array that does not begin at 0 but I can't get it to work. For example: $MyInfo = array(1 =27,68,31,19,40); will result in $MyInfo = 27 ... $MyInfo = 40...
5
by: sathyashrayan | last post by:
Dear group, The function to be used as follows: $links = "http://www.campaignindia.in/feature/analysis"; $tag1 = '<div class=feature-wrapper>'; $tag2 = '<h1><a href'; $tag3 = "</a>"; $op =...
8
by: vinpkl | last post by:
hi all i want to use explode url for shotening my urls i have a url like http://localhost/vineet/products.php?dealer_id=12&category_id=2 This is my navigation php code that has url...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.