rkm140 Posted September 28, 2009 Share Posted September 28, 2009 I have this peace of code that seems to work sometimes and sometimes it doesn't. $text = preg_replace( '#\[([2-9TJQKA]|10)([cdhs])\]#', "<img src='http://mypokerrails.com/forum1/cards/$1$2.png'>", $text ); Now what i mean but working sometime and sometimes not. First off this is suppose to only change the letter or number combination within then [ ] and it is changing letter and number combos that are posted outside the [ ] second, it will change the letter and number combos within the [ ] but within the same post it it skips some. as shown in the image below. Now here is part of the post prior to being submitted. What i have found is if i go in and force a new space between say Jd and Jc and submit it will show correctly. However member of the forum are not going to know to do this and it should work seamlessly with out the user needed to do any extra work. can someone please help me figure this out. Dealt to Ceewyl [8s Jd] [Jc] Dealt to art of ace [6h 9h] [9c] art of ace: bets $20 karelli has returned Ceewyl: calls $20 *** 6th STREET *** Dealt to Ceewyl [8s Jd Jc] [4d] Dealt to art of ace [6h 9h 9c] [Kd] art of ace: checks Ceewyl: bets $20 art of ace: calls $20 *** RIVER *** art of ace: checks Ceewyl: checks *** SHOW DOWN *** Ceewyl: shows [5d As 8s Jd Jc 4d Qh] (Lo: J,8,5,4,A) art of ace: shows [Ad 3c 6h 9h 9c Kd 4s] (Lo: 9,6,4,3,A) Quote Link to comment https://forums.phpfreaks.com/topic/175851-help-with-this-issue/ Share on other sites More sharing options...
rkm140 Posted September 28, 2009 Author Share Posted September 28, 2009 Thanks for putting this in the correct area. I apologize for missposting it. Quote Link to comment https://forums.phpfreaks.com/topic/175851-help-with-this-issue/#findComment-926587 Share on other sites More sharing options...
nrg_alpha Posted September 28, 2009 Share Posted September 28, 2009 Hmm.. I think I would tackle this issue like so... Example: $text = <<<EOF Dealt to Ceewyl [8s Jd Jc] [4d] Dealt to art of ace [6h 9h 9c] [Kd][Kg] EOF; function graphicCards($cardAbbreviations){ $arr = preg_split('#[\[\]\s]#', $cardAbbreviations[0], -1, PREG_SPLIT_NO_EMPTY); $image = ''; foreach($arr as $val){ $image .= "<img src='http://mypokerrails.com/forum1/cards/$val.png'>"; } return $image; } $text = preg_replace_callback('#\[(??:[2-9TJQKA]|10)(?:[cdhs])\s?)+\]#', 'graphicCards', $text); echo $text; So the idea here is that preg_replace searches for [, followed by the card abbreviation sequence (once or more times), then closed by ] into a function called graphicCards(); In here, I preg_split off any [, spaces and ] (which leaves me with simply the card abbreviations, like 8c, or Kd for example..) then use a blank variable $image to append the images together and simply return that end result. This way, whether there is one card abbreviation between [ and ] or multiple ones, it should get it. Note I deliberately put an invalid card abbreviation [Kg] in the sample heredoc string.. just to see if it would be ignored (which it is). This all also assumes you don't want to see the [ and ] characters surrounding the actual card graphics. If you do, simply use this version of the graphicCards function instead: function graphicCards($cardAbbreviations){ $arr = preg_split('#[\[\]\s]#', $cardAbbreviations[0], -1, PREG_SPLIT_NO_EMPTY); $image = '['; foreach($arr as $val){ $image .= "<img src='http://mypokerrails.com/forum1/cards/$val.png'>"; } $image .= ']'; return $image; } EDIT - Sorry for the constant edits... seems like the php code tags are fubaring some aspects of the code.. so when I tried using simply the code tags, it worked... Quote Link to comment https://forums.phpfreaks.com/topic/175851-help-with-this-issue/#findComment-926618 Share on other sites More sharing options...
.josh Posted September 28, 2009 Share Posted September 28, 2009 hmmm...does your code actually have several cards within a single set of brackets, or does each card wrapped around with its own set of brackets? IOW do you really have it like this: [6h 9h 9c] [Kd][Kg] or are all of the cards in the string really like this? [6h] [9h] [9c] [Kd][Kg] Quote Link to comment https://forums.phpfreaks.com/topic/175851-help-with-this-issue/#findComment-926620 Share on other sites More sharing options...
rkm140 Posted September 29, 2009 Author Share Posted September 29, 2009 It depends some will all be with one set of [ ] other will be in sepreate set I tried this code $text = <<<EOF Dealt to Ceewyl [8s Jd Jc] [4d] Dealt to art of ace [6h 9h 9c] [Kd][Kg] EOF; function graphicCards($cardAbbreviations){ $arr = preg_split('#[\[\]\s]#', $cardAbbreviations[0], -1, PREG_SPLIT_NO_EMPTY); $image = ''; foreach($arr as $val){ $image .= "<img src='http://mypokerrails.com/forum1/cards/$val.png'>"; } return $image; } $text = preg_replace_callback('#\[(??:[2-9TJQKA]|10)(?:[cdhs])\s?)+\]#', 'graphicCards', $text); echo $text; And i get this error Quote Link to comment https://forums.phpfreaks.com/topic/175851-help-with-this-issue/#findComment-926702 Share on other sites More sharing options...
rkm140 Posted September 29, 2009 Author Share Posted September 29, 2009 Using this gives me this error function graphicCards($cardAbbreviations){ $arr = preg_split('#[\[\]\s]#', $cardAbbreviations[0], -1, PREG_SPLIT_NO_EMPTY); $image = '['; foreach($arr as $val){ $image .= "<img src='http://mypokerrails.com/forum1/cards/$val.png'>"; } $image .= ']'; return $image; } Fatal error: Cannot redeclare graphiccards() (previously declared in /home/mypoker2/public_html/forum1/includes/class_postbit.php(294) : eval()'d code:23) in /home/mypoker2/public_html/forum1/includes/class_postbit.php(294) : eval()'d code on line 31 Quote Link to comment https://forums.phpfreaks.com/topic/175851-help-with-this-issue/#findComment-926703 Share on other sites More sharing options...
rkm140 Posted September 29, 2009 Author Share Posted September 29, 2009 Below is the original trext that will be placed in the post. Remeber this will all be similar. The cards will change and the players names and chip stack will change. PokerStars Game #33194475302: Razz Limit ($10/$20 USD) - 2009/09/23 15:08:17 ET Table 'Tselina' 8-max Seat 1: AkuAku ($115 in chips) Seat 2: Ceewyl ($464 in chips) Seat 3: kissyao389 ($591 in chips) Seat 4: caddymans ($210 in chips) Seat 5: bjao ($230 in chips) Seat 6: thx_dealer ($1045 in chips) Seat 7: art of ace ($305 in chips) AkuAku: posts the ante $1 Ceewyl: posts the ante $1 kissyao389: posts the ante $1 caddymans: posts the ante $1 bjao: posts the ante $1 thx_dealer: posts the ante $1 art of ace: posts the ante $1 *** 3rd STREET *** Dealt to AkuAku [Kc] Dealt to Ceewyl [8s] Dealt to kissyao389 [5h] Dealt to caddymans [Jh] Dealt to bjao [3h] Dealt to thx_dealer [Tc] Dealt to art of ace [6h] AkuAku: brings in for $3 Ceewyl: calls $3 kissyao389: folds caddymans: folds bjao: folds thx_dealer: folds art of ace: raises $7 to $10 AkuAku: folds Ceewyl: calls $7 *** 4th STREET *** Dealt to Ceewyl [8s] [Jd] Dealt to art of ace [6h] [9h] art of ace: bets $10 Ceewyl: calls $10 *** 5th STREET *** Dealt to Ceewyl [8s Jd] [Jc] Dealt to art of ace [6h 9h] [9c] art of ace: bets $20 karelli has returned Ceewyl: calls $20 *** 6th STREET *** Dealt to Ceewyl [8s Jd Jc] [4d] Dealt to art of ace [6h 9h 9c] [Kd] art of ace: checks Ceewyl: bets $20 art of ace: calls $20 *** RIVER *** art of ace: checks Ceewyl: checks *** SHOW DOWN *** Ceewyl: shows [5d As 8s Jd Jc 4d Qh] (Lo: J,8,5,4,A) art of ace: shows [Ad 3c 6h 9h 9c Kd 4s] (Lo: 9,6,4,3,A) art of ace collected $127 from pot *** SUMMARY *** Total pot $130 | Rake $3 Seat 1: AkuAku folded on the 3rd Street Seat 2: Ceewyl showed [5d As 8s Jd Jc 4d Qh] and lost with Lo: J,8,5,4,A Seat 3: kissyao389 folded on the 3rd Street (didn't bet) Seat 4: caddymans folded on the 3rd Street (didn't bet) Seat 5: bjao folded on the 3rd Street (didn't bet) Seat 6: thx_dealer folded on the 3rd Street (didn't bet) Seat 7: art of ace showed [Ad 3c 6h 9h 9c Kd 4s] and won ($127) with Lo: 9,6,4,3,A Quote Link to comment https://forums.phpfreaks.com/topic/175851-help-with-this-issue/#findComment-926704 Share on other sites More sharing options...
nrg_alpha Posted September 29, 2009 Share Posted September 29, 2009 I don't need that mountain of post info. You are getting a fatal redeclaring error.. sounds like you are declaring the function in more than one source.. Perhaps in your page as well as in an include file? Put the function in a single include file, and use include_once() or require_once() once prior to needing that function called. So the include file could be like: <?php function processCards($txt){ $txt = preg_replace_callback('#\[(??:[2-9TJQKA]|10)[cdhs]\s?)+\]#', 'graphicCards', $txt); echo nl2br($txt) . "<br />\n"; } function graphicCards($cardAbbreviations){ $arr = preg_split('#[\[\]\s]#', $cardAbbreviations[0], -1, PREG_SPLIT_NO_EMPTY); $image = ''; foreach($arr as $val){ $image .= "<img src='http://mypokerrails.com/forum1/cards/$val.png'>"; } return $image; } ?> and simply pass your entire post variable into processCards. If it's a class you want, you could perhaps use that include file to have this instead: <?php class Cards { private $input; function __construct($text) { $this->input = preg_replace_callback('#\[(??:[2-9TJQKA]|10)[cdhs]\s?)+\]#', array($this, 'graphicCards'), $text); echo $this->input . "<br />\n"; // final styling with card images in place } function graphicCards($cardAbbreviations){ $arr = preg_split('#[\[\]\s]#', $cardAbbreviations[0], -1, PREG_SPLIT_NO_EMPTY); $image = ''; foreach($arr as $val){ $image .= "<img src='http://mypokerrails.com/forum1/cards/$val.png'>"; } return $image; } } ?> and create a new object with the post variable being passed into the constructor. Quote Link to comment https://forums.phpfreaks.com/topic/175851-help-with-this-issue/#findComment-926767 Share on other sites More sharing options...
rkm140 Posted September 29, 2009 Author Share Posted September 29, 2009 I tied both of those and i am getting this error. Parse error: syntax error, unexpected '<' in /home/mypoker2/public_html/forum1/includes/class_postbit.php(294) : eval()'d code on line 23 Quote Link to comment https://forums.phpfreaks.com/topic/175851-help-with-this-issue/#findComment-927069 Share on other sites More sharing options...
rkm140 Posted September 29, 2009 Author Share Posted September 29, 2009 Below is an image of what i am doing within the vbulletin software. Maybe i am doing it wrong or something. But i have tried everything so far and it still isn't working. Quote Link to comment https://forums.phpfreaks.com/topic/175851-help-with-this-issue/#findComment-927072 Share on other sites More sharing options...
nrg_alpha Posted September 29, 2009 Share Posted September 29, 2009 Truth be told, I'm not familiar with vBulletin and it's plug-in system. Looking at the bottom of the screenshot, in the panel Plugin PHP Code, does this require the use of <?php and ?> ? Or can you omit those and the vBulletin system will understand that all the rest of that code in there is PHP and treat it accordingly? Again, sorry I'm not familiar with that system.. perhaps contacting vBulletin themselves with regards to this matter? Quote Link to comment https://forums.phpfreaks.com/topic/175851-help-with-this-issue/#findComment-927089 Share on other sites More sharing options...
rkm140 Posted September 29, 2009 Author Share Posted September 29, 2009 If i understand what your asking. If i remove the <?php and the ?> will it work it. No i tried this and only to get this error Fatal error: Cannot redeclare processcards() (previously declared in /home/mypoker2/public_html/forum1/includes/class_postbit.php(294) : eval()'d code:23) in /home/mypoker2/public_html/forum1/includes/class_postbit.php(294) : eval()'d code on line 26 Quote Link to comment https://forums.phpfreaks.com/topic/175851-help-with-this-issue/#findComment-927107 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.