clown[NOR] Posted January 28, 2008 Share Posted January 28, 2008 as i've said in an earlier post i'm working on a sript that will show the player score for a CoD4 game server... highest to lowest the past hour... so i got some help in here, but what i wonder... this code here foreach ($text as $line) { preg_match('/(\d\d:\d\d:\d\d)\] (.+) killed/',$line,$match); $blamtime=$match[1]; $person=$match[2]; if($now-$blamtime<=$hourago) { $score[$person]++; $time[$blamtime]++; } } i'm working with a 24-hour time.. so when it goes to midnight it goes back to 00.. wont that mess up? since 00 is less than 23? how can i work around that? Quote Link to comment https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/ Share on other sites More sharing options...
cooldude832 Posted January 28, 2008 Share Posted January 28, 2008 just replace time of midnight with time of 24 or do a time based sort instead of a integer/float based sort Quote Link to comment https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/#findComment-450945 Share on other sites More sharing options...
clown[NOR] Posted January 28, 2008 Author Share Posted January 28, 2008 oh so... str_replace("00","24",$blamtime) <--- like that? Quote Link to comment https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/#findComment-450948 Share on other sites More sharing options...
cooldude832 Posted January 28, 2008 Share Posted January 28, 2008 sure Quote Link to comment https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/#findComment-450953 Share on other sites More sharing options...
clown[NOR] Posted January 28, 2008 Author Share Posted January 28, 2008 so this should work without any issues? $blamtime = str_replace("00","24",$blamtime); if($now-$blamtime<=$hourago) { $score[$person]++; $time[$blamtime]++; } Quote Link to comment https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/#findComment-450959 Share on other sites More sharing options...
laffin Posted January 28, 2008 Share Posted January 28, 2008 uhm, not quite, as that might also replace the minutes and seconds if they are 00 if(substr($blamtime,0,2)=="00") substr_replace($blamtime,"24",0,0); Quote Link to comment https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/#findComment-450990 Share on other sites More sharing options...
clown[NOR] Posted January 28, 2008 Author Share Posted January 28, 2008 thanks you laffin =) Quote Link to comment https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/#findComment-451376 Share on other sites More sharing options...
clown[NOR] Posted January 28, 2008 Author Share Posted January 28, 2008 next question.. it's now 18:23 here... (didnt add the secs now)... but it still shows the time that was yesterday at 23 and 00 etc... how can i change the regex to catch the date also so i can make a if statement that skips everything that was yesterday? this is the complete code i've got now: <?php function getKills($server_id) { // One hour ago $n_hour = date("H")-1; $n_ms = date("i:s"); $hourago = $n_hour.":".$n_ms; $filename = "http://ts.1337gamer.no:28950/cod-server-".$server_id."/Kills.txt"; $text = file($filename); foreach ($text as $line) { preg_match('/(\d\d:\d\d:\d\d)\] (.+) killed/',$line,$match); $k_time=$match[1]; $person=$match[2]; if(substr($k_time,0,2)== "00") { substr_replace($k_time,"24",0,0); } if($now-$k_time<=$hourago) { $score[$person]++; } } arsort($score); echo ' <table border="1" cellspacing="0" cellpadding="0" width="300 bordercolor="#000000"> <tr> <td width="150"><strong>Player</strong></td> <td width="50"><strong>Kills</strong></td> </tr> '; foreach ($score as $killer => $kills) { if (!empty($killer)) { //echo "<strong>$killer</strong> has <strong>$kills</strong> kills.<br />"; echo ' <tr> <td width="150">'.$killer.'</td> <td width="50">'.$kills.'</td> </tr> '; } } echo '</table>'; } ?> Thanks In Advance - Clown Quote Link to comment https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/#findComment-451382 Share on other sites More sharing options...
clown[NOR] Posted January 28, 2008 Author Share Posted January 28, 2008 should i make the preg_match look something like this? preg_match('/ \[\d\d.\d\d.\d\d\)(\d\d:\d\d:\d\d)\] (.+) killed/',$line,$match); it's prob WAY off... i have no clue about regex so that's just a wild guess Quote Link to comment https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/#findComment-451390 Share on other sites More sharing options...
clown[NOR] Posted January 28, 2008 Author Share Posted January 28, 2008 bump? Quote Link to comment https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/#findComment-451429 Share on other sites More sharing options...
laffin Posted January 28, 2008 Share Posted January 28, 2008 u might be better off converting to time() format. than it wud be easier to calculate Quote Link to comment https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/#findComment-451474 Share on other sites More sharing options...
clown[NOR] Posted January 28, 2008 Author Share Posted January 28, 2008 ok ill try that out.. but atm i just cant figure out how to pull out the date with regex... been going crazy @ google and still no luck so until i can get the date i' stuck file setup: [28.01.2008 19:44:08] Omega|IzNoGood killed [1337]sleggis with unkown Zone:Headshoot Damage:55 [28.01.2008 19:44:24] [1337]sleggis killed dsr.encke with m4 silencer Zone:Torso lower Damage:42 [28.01.2008 19:44:44] dsr.encke killed Trym with unkown Zone:unkown Damage:170 [28.01.2008 19:44:47] Omega|Mora di killed Trym with ak47 Silencer Zone:Torso lower Damage:56 [28.01.2008 19:45:05] Omega|Mora di killed dsr.gnawler with Grenade Zone:unkown Damage:192 [28.01.2008 19:45:06] [1337]sleggis killed *HMC*Antman with Grenade Zone:unkown Damage:285 [28.01.2008 19:45:17] Banko.Maestro killed [1337]PuZuR with mp5 silencer Zone:Torso upper Damage:136 code: foreach ($text as $line) { preg_match('/(\d\d:\d\d:\d\d)\] (.+) killed/',$line,$match); $k_time=$match[1]; $person=$match[2]; //echo $match[2]."<br />"; $score[$person]++; } if anyone could help me out with the preg_match i think i'll be able to fix the if's myself Quote Link to comment https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/#findComment-451495 Share on other sites More sharing options...
laffin Posted January 28, 2008 Share Posted January 28, 2008 preg_match("@^\[(\d{2}.\d{2}.\d{4} \d{2}:\d{2}:\d{2})\] (.+?) killed (.+?) with (.+) Damage:(\d{1,})$@i",$file,$matches); shud return $matches[1] date/time $matches[2] killer $matches[3] killee $matches[4] damage done Quote Link to comment https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/#findComment-451514 Share on other sites More sharing options...
clown[NOR] Posted January 28, 2008 Author Share Posted January 28, 2008 that returned nothing ... foreach ($text as $line) { preg_match("@^\[(\d{2}.\d{2}.\d{4} \d{2}:\d{2}:\d{2})\] (.+?) killed (.+?) with (.+) Damage:(\d{1,})$@i",$line,$match); $k_time = $match[1]; $person = $match[2]; echo $match[1]." - ".$match[2]." - ".$match[3]." - ".$match[4]."<br />"; $score[$person]++; } output - - - i really wanna learn how to setup a regex string thingy... is there a tutorial for 100% noobs? i mean like so detailed that noone can read trough the whole thing and at the end still dont understand how to do it =) Quote Link to comment https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/#findComment-451523 Share on other sites More sharing options...
clown[NOR] Posted January 28, 2008 Author Share Posted January 28, 2008 fixed it by editing your code into the old one.. this is the result: preg_match('/\[(\d{2}.\d{2}.\d{4} \d{2}:\d{2}:\d{2})\] (.+) killed/',$line,$match); thanks for your help laffin Quote Link to comment https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/#findComment-451534 Share on other sites More sharing options...
laffin Posted January 28, 2008 Share Posted January 28, 2008 shure thing, tell me how yer project is coming. Quote Link to comment https://forums.phpfreaks.com/topic/88135-solved-got-a-pretty-simple-question/#findComment-451553 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.