Jump to content

Need help with a small existing script.


HHawk

Recommended Posts

The original creator of this small PHP script stopped working on it and I don't know much about PHP, so I need some help.

 

Here is the script:

 

<?php
$fourcolor = 0;

function pokerhand($text) {
  // Only take things that are between the tag.
  $ret = preg_replace("'<pokerhand>(\w*)</pokerhand>'e", "replace_card('\\1')", $text);

  return $ret;
}

function replace_card($text) {

  $ret = "";
  $a = preg_split('//', $text, -1, PREG_SPLIT_NO_EMPTY);

  foreach($a as $value) {
    if(!strcmp($value, "c")) {
      $ret .=  '<span class="clubs">♣ </span>';;
    } else if(!strcmp($value, "d")) {
      $ret .=  '<span class="diamonds">♦ </span>';
    } else if(!strcmp($value, "h")) {
      $ret .=  '<span class="hearts">♥ </span>';
    } else if(!strcmp($value, "s")) {
      $ret .=  '<span class="spades">♠ </span>';
    } else {
     $ret .= $value;
    }
  }
  return($ret);
}

function pokerhand_head() {
  global $fourcolor;
  $diamond = $fourcolor ? "blue" : "red";
  $club = $fourcolor ? "green" : "black";

       echo "
<style type='text/css'>
.diamonds {
   color: ".$diamond.";
   font-size: 15px;
}
.clubs {
   color: ".$club.";
   font-size: 15px;
}
.hearts {
   color: red;
   font-size: 15px;
}
.spades {
  color: black;
  font-size: 15px;
}
</style>
";

}

add_filter('the_content', 'pokerhand');
add_filter('the_excerpt', 'pokerhand');
add_filter('comment_text', 'pokerhand');
add_action('wp_head', 'pokerhand_head');
?>

 

As you can see it's a wordpress plugin script.

 

The script itself works without problems, however it doesn't "color" the first number/graphic in front of the spade, diamond, heart or club.

 

Sorry for my bad english, but I dunno how to describe it better. Maybe an example will help.

 

Example

 

When you use:

 

<pokerhand>Js3h</pokerhand>

 

It will show this: J♠ 3

 

But I want it to show like this: J♠ 3♥

 

As you can see, the number in front of the 3 is also colored red (of course the same goes for diamonds).

 

And if possible, I want the output to be bold. Please help. Thanks!

Link to comment
https://forums.phpfreaks.com/topic/147741-need-help-with-a-small-existing-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.