Jump to content

Expert needed! Trying to cycle through array and replace with predefined regex rules


gregchet

Recommended Posts

PHP ARRAY/REGEX PRO NEEDED!! HEEEEELP!

In short, I'm trying to re-create a Poker Stars hand history convertor I made a while back. I used to use ereg_replace on a multi-line variable of text, but there were little annoying problems that kept popping up. I decided to split the multi-line variable into an array so that each line was now its own variable, and I figure this will make the searching and replacing much more accurate.

This is eventually all going to be database driven, but for this example I've turned it into an array. If I can get help on this, I'll have no problem converting it over to the database version.

I'm basically trying to take a list of predefined REGEX rules (and their replacements), and then if these rules much the individual lines in the newly created array, replace them (so every rule should be checked against every line, and replaced if it matches).

I must be missing something here, possibly due to the fact that I've been sleep deprived for quite some time now :P (but no, not because of this convertor, hehe)

If any pros wanna help me out with this, it would be GREATLY appreciated.


<?php
// This is an include that I use within another file, and the "$new_hand" variable is already populated with a multi-line block of text

$rule[0] = "PokerStars Game \#([0-9]*): Tournament \#([0-9]*), Freeroll Hold'em No Limit - Level ([0-9a-zA-Z]*) \(([0-9]*)/([0-9]*)\) - ([0-9]*)/([0-9]*)/([0-9]*) - ([0-9]*):([0-9]*):([0-9]*) \(ET\)";

$rule_replacement[0] = "--------------------<BR><b>Hand Convertor v1.0 -- Poker Stars Tournament</b><BR><BR><b>NL Texas Hold'em, Freeroll - Level \\3</b> (\\4/\\5)<BR><BR><b>Tournament </b>#\\2, <b>Game </b>#\\1, ";

$rule[1] = "TESTER PokerStars Game \#([0-9]*): Tournament \#([0-9]*), Freeroll Hold'em No Limit - Level ([0-9a-zA-Z]*) \(([0-9]*)/([0-9]*)\) - ([0-9]*)/([0-9]*)/([0-9]*) - ([0-9]*):([0-9]*):([0-9]*) \(ET\)";

$rule_replacement[1] = "TESTER --------------------<BR><b> Hand Convertor v1.0 -- Poker Stars Tournament</b><BR><BR><b>NL Texas Hold'em, Freeroll - Level \\3</b> (\\4/\\5)<BR><BR><b>Tournament </b>#\\2, <b>Game </b>#\\1, ";

// Split the multi-line variable into an array so that each line is now its own variable
$hand_test = split("\n", $new_hand);

$rule_count = count($rule);

foreach($hand_test as $ht) {

$count = 0;

while ($count <= $rule_count) {
$skibble[$count] = eregi_replace($rule[$count], $rule_replacement[$count], $ht);
$count++;
}
}
?>

At this point I'd like the "$skibble" variable to contain the old "$new_hand" information, except with the replaced, formatted text.

I'm sure I'm going to be incredibly embarassed when I see what I've done wrong here.
Link to comment
Share on other sites

You can ignore this post! Think I may have gotten it figured out based on some responses I got on another forum (just working out a small glitch now).

[a href=\"http://phpbuilder.com/board/showthread.php?p=10731261#post10731252\" target=\"_blank\"]http://phpbuilder.com/board/showthread.php...61#post10731252[/a]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.