Using an uploader form, Is it possible to upload and use the following style txt file: --------------- <name1> I have this error running from inside google <name1> name3 you know what address I've passed you last friday? <name2> hi. is there a COMMAND LINE svg editor for linux? <name2> i explain my problem <name3> no name1 <name1> xslt processors? custom scripts perhaps? <name4> but nothing out-of-the-box that I know of ---------------- and extract the names between < > and display each name's string count over all in the entire log file? for example: echo ('name1 = 209 characters typed'); echo ('name2 = 100 characters typed'); so on.. echo ('over all characters type X'); echo ('over X amount of users'); I basically want my existing IRC log file viewed as the example above. thanks in advanced.
Yes please, whenever you have time, I would like to learn how to do it, i'd greatly appreciate it. Thank you
Here is the code.. $myfile = ‘http://site.com/log/2.log’; $file_handle = fopen(â€http://site.com/log/2.logâ€, “râ€); $i=0; echoâ€<pre>â€; //i is number of lines to read while (!feof($file_handle)&&($i<8000)) { $line = fgets($file_handle); //prints the line echo $line; echoâ€<BR>â€; $i=$i+1; } echoâ€</pre>â€; fclose($file_handle); ?> PHP:
<?PHP $f=fopen('file.txt','r');//Read while(($data=fgets($f))!==false) { /* Preg_Match matches one time to a regular expression(perl) using preg_match_all finds multiple of the expression, but for this, we need it once. Expression explanation: ^ - Starts the expression -- must end with this too \< - since < is a command in regex, we escape it this is the < of <name> (.*) - Finds all data \> -- Same as the \< (space) - the space in the strings (.*) - same as above, gets all data. ^ - End the expression */ @preg_match('^\<(.*)\> (.*)^',$data,$match); if($match[1]!='') $array[$match[1]]+=strlen($match[2]); } /* foreach ($ArrayVariable as $KeyName => $KeyValue) Example: Our array has keys, they are the usernames Foreach loops through that array, each key is the "as $Keyname" the variable maybe named anything, but use something relavent for sanity sakes. Then the "=> $KeyValue" gives you the value of the key in the variable $KeyValue. Once again, this can be anything, but use relavent names */ foreach($array as $name => $number) { echo $name.' typed '.$number.' letters in this chat<br />'; } fclose($f) ?>
I have made a few slight changes and am having problems... But not with things I changed lol: <?PHP $file = 'log.txt'; //File to open $f=fopen($file,'r');//Read while(($data=fgets($f))!==false) { @preg_match("^\<(.*)\> (.*)^",$data,$match); if($match[1]!='') $array[$match[1]]+=strlen($match[2]); } foreach($array as $name => $number) { $html = htmlentities($name.' typed '.$number.' chars'); echo $html.'<br />'; } fclose($f) ?> PHP: I'm having one simple problem. Log file contains: <Name1> hi <Name2> !ghelp yourki <+GoogleBot> Name2: <Name2> what is yourki? <Name4> hiya Name1 Code (markup): I get an output as: Name1 typed 2 chars Name2 typed 14 chars +GoogleBot> Name2: <Name2 typed 18 chars Name4 typed 10 chars Code (markup): It should just give me an output of: Name1 typed 2 chars Name2 typed 14 chars +GoogleBot typed 32 chars Name4 typed 10 chars Code (markup): I think the problem is the +GoogleBot inserts <Name2> into the log and when the script runs, it gets confused at that line. Thanks in advanced for any help .
Solved, replaced: @preg_match("^\<(.*)\> (.*)^",$data,$match); with @preg_match("^\<(.*?)\> (.*)^",$data,$match); a pesky little question mark lol