PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old June 25th, 2004, 01:43 AM
craky craky is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 craky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
need help text parsing.

Hi all, basically im having great difficulties trying to parse a text files and build my array from it all, anyhow im not sure were the problem is totally but i think it may be in the preg_match_all or maybe it just wacked. anyhow heres a link to the file im trying to parse, http://24.235.247.34/log.txt , heres the code so far...

PHP Code:
<?php
define
('DATA_FILE''results.dat');
$result = array();
if (! isset(
$_GET['reset']))
  if (! 
$result unserialize(@file_get_contents(DATA_FILE))) {
    echo 
'Warning: Unable to open "'.DATA_FILE.'" for reading. Continuing anyway.<br />';
  }
if (isset(
$_GET['parse'])) {
     foreach (
glob('*.txt') as $strFilename) {
      if (
is_file($strFilename)) {
   
      
$strLog file_get_contents($strFilename);
      
$strLog str_replace( array("\n","\r\n"), "\r"$strLog );
      
preg_match_all'/-{40,}\r(.*?)\rD/'$strLog$arrMatches );
      foreach( 
$arrMatches[1] as $strWeapon ) {
      
$arrWeapon explode("\r"$strWeapon);
      foreach( 
$arrWeapon as $strData ) {
      if (
$strData) {
     
$arrData preg_split('/[\s]+/'trim($strData));
 
$result[$arrData[0]][$arrData[1]]['Gauntlet'] += $arrData[2];
 
$result[$arrData[0]][$arrData[1]]['MachineGun'] += $arrData[3];
 
$result[$arrData[0]][$arrData[1]]['Shotgun'] += $arrData[4];
 
$result[$arrData[0]][$arrData[1]]['G.Launcher'] += $arrData[5];
 
$result[$arrData[0]][$arrData[1]]['R.Launcher'] += $arrData[6];
 
$result[$arrData[0]][$arrData[1]]['LightningGun:'] += $arrData[7];
 
$result[$arrData[0]][$arrData[1]]['Railgun'] += $arrData[8];
 
$result[$arrData[0]][$arrData[1]]['Plasmagun'] += $arrData[9];
 
$result[$arrData[0]][$arrData[1]]['BFG'] += $arrData[10];
 
  } 
 } 

  
unlink($strFilename);
 }
}
     
    if(!
$fp fopen(DATA_FILE'w')) {
        echo 
'Error opening "'.DATA_FILE.'" for writing. Aborting.<br>';
        exit(
1);
    }
    if(!
fwrite($fpserialize($result))) {
        echo 
'Error writing contents to "'.DATA_FILE.'". Aborting.<br>';
        exit(
1);
    }
    
fclose($fp);
}
echo 
'<br>After:<br><pre>';
var_dump($result);
echo 
'</pre>';
?>


also here what my array looks likes so far, i can't seem to match the numbers with the weapons...

PHP Code:
array(7) {
  [
"Shotgun"]=>
  array(
1) {
    [
":"]=>
    array(
9) {
      [
"Gauntlet"]=>
      
float(7.5)
      [
"MachineGun"]=>
      
int(5)
      [
"Shotgun"]=>
      
int(7)
      [
"G.Launcher"]=>
      
int(0)
      [
"R.Launcher"]=>
      
int(18)
      [
"LightningGun:"]=>
      
int(2)
      [
"Railgun"]=>
      
int(0)
      [
"Plasmagun"]=>
      
int(0)
      [
"BFG"]=>
      
int(0)
    }
  } 


definatly doing something wrong here. any ideas?

Reply With Quote
  #2  
Old June 27th, 2004, 01:08 PM
craky craky is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Posts: 2 craky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Can anyone help me here please?

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > need help text parsing.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway