Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's your code with a few tiny changes that should help quite a bit</p> <ol> <li>Switched from <code>file()</code> to <code>fgets()</code>. This will load only a single line at a time into memory instead of every line from the file.</li> <li>Changed your calls to <code>preg_match()</code> to <code>stripos()</code> where applicable. Should be a tiny bit faster</li> <li>Moved the opening/closing of <code>$ourFileHandle</code> into the outer loop. This will <em>significantly</em> reduce the number of stat calls to the filesystem and should speed it up greatly.</li> </ol> <p>There are probably a lot of other optimizations that can be made in that monstrous if..else but i'll leave those up to another SOer (or you)</p> <pre><code>$fileselection = scandir_recursive('HH_new'); foreach ($fileselection as $extractedArray) { $tableName = basename( $extractedArray ); // Table name $handle = fopen( $extractedArray, 'r' ); $ourFileHandle = fopen("HH_newest/".$tableName.".txt", 'a') or die("can't open file"); while ( $line = fgets( $handle ) ) { if ( false !== stripos( $line, '(all-in)' ) ) { $line = stristr($line, ' (all-in)', true) .', and is all in'; $allin = ', and is all in'; } else { $allin = ''; } if ( preg_match('/posts the small blind of \$[\d\.]+/i' , $line ) ) { $player = stristr($line, ' posts ', true); $betValue = substr(stristr($line, '$'), 1); $bettingMatrix[$player]['betTotal'] = $betValue; } else if(preg_match('/posts the big blind of \$[\d\.]+/i' , $line)) { $player = stristr($line, ' posts ', true); $betValue = substr(stristr($line, '$'), 1); $bettingMatrix[$player]['betTotal'] = $betValue; } else if(preg_match('/\S+ raises /i' , $line)) { $player = stristr($line, ' raises ', true); $betValue = substr(strstr($line, '$'), 1); $bettingMatrix[$player]['betTotal'] = $betValue; //total bet this hand (shortcut) } else if(preg_match('/\S+ bets /i' , $line)) { $player = stristr($line, ' bets ', true); $betValue = substr(strstr($line, '$'), 1); $bettingMatrix[$player]['betTotal'] = $betValue; //total bet this hand (shortcut) } else if(preg_match('/\S+ calls /i' , $line)) { $player = stristr($line, ' calls ', true); $betValue = substr(stristr($line, '$'), 1); $callValue = $betValue - $bettingMatrix[$player]['betTotal']; //actual amount called $bettingMatrix[$player]['betTotal'] = $betValue; $line = stristr($line, '$', true)."\$".$callValue.$allin; $allin = ''; } else if(preg_match('/(\*\*\* (Flop|Turn|River))|(Full Tilt Poker)/i' , $line)) { unset($bettingMatrix); //zero $betValue } else if ( FALSE !== stripos( $line, '*** FLOP ***' ) ) { $flop = substr(stristr($line, '['), 0, -2); $line = '*** FLOP *** '. $flop; } else if ( FALSE !== stripos( $line, '*** TURN ***' ) ) { $turn = substr(stristr($line, '['), 0, -2); $line = '*** TURN *** '. $flop .' '. $turn; } else if ( FALSE !== stripos( $line, '*** RIVER ***' ) ) { $river = substr(stristr($line, '['), 0, -2); $line = '*** RIVER *** '. substr($flop, 0, -1) .' '. substr($turn, 1) .' '. $river; } else { } fwrite($ourFileHandle, $line); } fclose( $handle ); fclose( $ourFileHandle ); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload