Ryan Partington.com
January 06, 2009, 09:14:39 *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: SMF - Just Installed!
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Pulling specific data from a file  (Read 406 times)
rick111
Three Ones
Administrator
Jr. Member
*****

Karma: +3/-3
Posts: 90



« on: November 13, 2008, 22:29:36 »

I've got a file on my centos box (var/lib/webalizer/webalizer.hist) that contains the following data

Code:
1 2008 34761 28429 4084 602802 1 31 11953 4100
2 2008 30260 26357 2524 946628 1 29 10519 3583
3 2008 60366 53570 3529 2337832 1 31 18149 7375
4 2008 51558 46152 3216 1078036 1 30 17895 7816
5 2008 53368 37689 2691 934830 1 31 28372 6324
6 2008 35208 23378 2454 428751 1 30 20057 6452
7 2008 28908 20103 1633 407008 1 31 12240 5204
8 2008 74651 58464 1449 755570 1 31 20464 5290
9 2008 50860 42680 1487 651686 1 30 15285 6098
10 2008 33675 26966 1418 556143 1 31 14719 6177
11 2008 17088 14320 730 247092 1 13 8636 2615
12 2007 36010 29503 6964 8716984 1 31 10685 4424

The first number on each line is the month, so for example the line beginning with 11, is the month of November. The next number to the right of 11 is how many hits my website has had that month, for example, in November so far, I've had 17088 hits.

I'd like to write a little script which can pull the number of hits out for the current month, and then display this number on my homepage. Any ideas?

Cheers
Ryan Partington

 Shocked
Logged

<impl> CAPS LOCK IS CRUISE CONTROL FOR COOL
bigtime
Galactic Commander
GK
Jr. Member
*

Karma: +1/-1
Posts: 66



« Reply #1 on: November 13, 2008, 23:36:02 »

Code:

<?php
// puts contents of file into array
$text file('webalizer.txt');
$text=array_reverse($text);

// splits contents into lines
foreach($text as $line) {
        
// split lines into individual record
$Stringarray=explode(" "$line); 

if ($Stringarray[0]==date("n")) {
$Value1=$Stringarray[0];
$Value2=$Stringarray[1];
$Value3=$Stringarray[2];
$Value4=$Stringarray[3];
$Value5=$Stringarray[4];
$Value6=$Stringarray[5];
$Value7=$Stringarray[6];
$Value8=$Stringarray[7];
$Value9=$Stringarray[8];
$Value10=$Stringarray[9];
}
}

//echo out required record
echo $Value3;
?>


« Last Edit: November 13, 2008, 23:40:19 by bigtime » Logged
bigtime
Galactic Commander
GK
Jr. Member
*

Karma: +1/-1
Posts: 66



« Reply #2 on: November 14, 2008, 02:47:15 »

just copy that code into your index and echo out $Value3 where you want the hitcounter to be displayed.

It can also be adapted to create a dashboard on the visitor stats for your site.
Logged
rick111
Three Ones
Administrator
Jr. Member
*****

Karma: +3/-3
Posts: 90



« Reply #3 on: November 14, 2008, 06:33:05 »

That works, pure and unedited it worked first time!  Shocked

Impressive stuff Michael. Will blog this is the near future.

Thanks
Logged

<impl> CAPS LOCK IS CRUISE CONTROL FOR COOL
bigtime
Galactic Commander
GK
Jr. Member
*

Karma: +1/-1
Posts: 66



« Reply #4 on: November 14, 2008, 07:08:57 »

no probls mate  Cheesy

The first dev support post, hopefully more to come  Wink
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.6 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!