Just started

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
cschotch
Forum Newbie
Posts: 8
Joined: Thu Dec 12, 2002 4:56 pm

Just started

Post by cschotch »

Ok..I just started about a month ago. While learning this...HTML, Java, MySql and a host of other things to make my website looking good. Its doing great and I have to thank everyone for posting on this website I use this as a good resource. But I have a roadblock that I don't know what I need to do first?
I have a simple text log file from a gaming server that I need a php script to search through the file, count how many times something shows up(a particular name, or more then one actually) and tell me what it came up with. I'm pretty sure php will do this considering what I have done with it so far but can someone throw me a bone and tell me where to start?...

Oh by the way take a look at the website and see what you think....

http://www.invisiblewarriors.com
oldtimer
Forum Contributor
Posts: 204
Joined: Sun Nov 03, 2002 8:21 pm
Location: Washington State

Post by oldtimer »

What type of game?

You can use explode to call up the file. After that it depends. Are you looking for something particular or just to group everything together.
cschotch
Forum Newbie
Posts: 8
Joined: Thu Dec 12, 2002 4:56 pm

Post by cschotch »

Medal of honor allied assault. I have a server log file and need to open the file then look (search) through it..find a team members name, then count that, then keep looking for another team members name, count that etc.... till all the team members have been found or it has looked through the whole file. Then output that to a page and tell me how many times(if any) it found of each team member.
cschotch
Forum Newbie
Posts: 8
Joined: Thu Dec 12, 2002 4:56 pm

Post by cschotch »

Ok first time doing anything with a file...this works

Code: Select all

<?php
// Open the text file 
$filename = "endofday.txt"; 
$fp = fopen($filename,"r"); 

// Read the file 
$end_report = fread($fp, filesize($filename)); 

// Define search 
$needle1 = "WhereArtThou"; 
$needle2 = "BlackBart"; 

// Count the number of occurences 
$num_occurs1 = substr_count($end_report, $needle1);
$num_occurs2 = substr_count($end_report, $needle2); 

// Set the total number of occurences 
$total1 = $num_occurs1; 
$total2 = $num_occurs2; 

print "WhereArtThou $total1 <br>";
print "BlackBart $total2 <br>";

fclose($fp);

?>
But I have approximately 30+ more names to look for in this file. What would be the easer way to write a loop program.
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post by nathus »

Could creat an associative array, where each person's name is a key.

Code: Select all

<?php

// Open the text file 
$filename = "endofday.txt"; 
$fp = fopen($filename,"r") or die("Failed!"); 

// Read the file 
$end_report = fread($fp, filesize($filename)); 

// Define search
$names['BlackBart'] = 0;
$names['WhereArtThou'] = 0;

// Count the number of occurences 
foreach(array_keys($names) as $value){
    $names[$value] = substr_count($end_report, $value);
} 

// Set the total number of occurences 
foreach($names as $key=>$value) {
    echo "$key: $names[$key] <br />\n";
}
fclose($fp); 


?>
cschotch
Forum Newbie
Posts: 8
Joined: Thu Dec 12, 2002 4:56 pm

Post by cschotch »

I thought that an array might solve the problem but i kept trying to do a while statement, never thought to use foreach.
Thanks alot....that works now.....
all i have to do is an interface to be able to work it into a access script so I can have individual days and do a table layout and im done......
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I don't want to interrupt your affords in scripting php but you might take a look at http://stats.clanfx.com/ ;)
cschotch
Forum Newbie
Posts: 8
Joined: Thu Dec 12, 2002 4:56 pm

Post by cschotch »

Understandable and it is a nice stats program. But one of my own team members has made a server tool Called MOHAA Counter Intelligence. Basically I'm taking a log file generated by that and (hopefully) have a form that takes that log file and interprets the data , see who was on, and then output it to html. I have the output I just need to work on the form and Itll be complete.
cschotch
Forum Newbie
Posts: 8
Joined: Thu Dec 12, 2002 4:56 pm

Post by cschotch »

ok I got a form down to where someone can upload a file and retrieve results from the previous scripts......Now when doing multiple files(like having 7 files for monda, tuesday, etc) do you need to upload, create a array then use the foreach to go through each file or is this not possible?...I tried just doing two and it doesnt seem to want to count either one....
Post Reply