CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   Post a PHP snippet (http://www.codingforums.com/forumdisplay.php?f=41)
-   -   52 Playing Card Deck Random Hand Draw (7-Card) [With Images] (http://www.codingforums.com/showthread.php?t=266395)

skill3d 06-27-2012 03:09 AM

52 Playing Card Deck Random Hand Draw (7-Card) [With Images]
 
This is a pretty straight forward script with images, you refresh the page or click the red face-down card to get a new hand. Pulls 7 Random cards from the deck, Clubs, Diamonds, Hearts, or Spades for the Suit and Ace, 1, 2, 3, 4, .. 9, 10, Jack, Queen, King for the number. This is a basic script using mainly PHP with some HTMl for tables, and Javascript for refreshing the page. This can be used as is, or someone can take it further possibly by making it multiplayer, and or more interactive to bring people together in a game of cards or something. Version 1.0, this took me about 25 minutes to complete, I'm going to be working on adding individual card re-draws and things like that in the future. Below is a picture along with download link(s).

http://i50.tinypic.com/34ou0r5.png

Download Links
Uppit Download

This is my first release and I'd much appreciate any feedback you have, i'm somewhat new to PHP and this is the first thing i've release so let me know your thoughts! Thanks everyone.

Credits:

95% ~ Me / Skill3d
- Doing the coding and putting the script together.
5% ~ Jesse Fuchs and Tom Hart
- Card Images that are included in the package from This Website

PHP Code:

<?php

$suits 
= array('Clubs''Diamonds''Hearts''Spades');
$cards = array('Ace'2345678910'Jack''Queen''King');

    echo 
"</br>";
    
$randcard rand(012);
    
$randsuit rand(03);
    
    
$randcard2 rand(012);
    
$randsuit2 rand(03);
    
    
$randcard3 rand(012);
    
$randsuit3 rand(03);
    
    
$randcard4 rand(012);
    
$randsuit4 rand(03);
    
    
$randcard5 rand(012);
    
$randsuit5 rand(03);
    
    
$randcard6 rand(012);
    
$randsuit6 rand(03);
    
    
$randcard7 rand(012);
    
$randsuit7 rand(03);
?>
<html>
<head>

<script type="text/javascript">
function reloadPage()
  {
  window.location.reload()
  }
</script>
    <title>Five Card Draw</title>
</head>
<body>
<center>
<a href="" onclick="reloadPage()" style="padding-bottom: 0px; text-decoration: none;"><font color="red"><h3>Re-Draw</h3></font><img src="images/back-red-150-1.png" /></a></br></br>
<!-- CARD IMAGES -->
<!-- CARD 1 -->
<?php
$suit 
'';
$card '';

if(
$randsuit == 0){
$suit 'clubs';
} else if(
$randsuit == 1){
$suit 'diamonds';
} else if(
$randsuit == 2){
$suit 'hearts';
} else if(
$randsuit == 3){
$suit 'spades';
}

if(
$randcard == 10){
$card 'j';
} else if(
$randcard == 11){
$card 'q';
} else if(
$randcard == 12){
$card 'k';
} else if(
$randcard == 0){
$card 'a';
} else if(
$randcard == 1){
$card '2';
} else if(
$randcard == 2){
$card '3';
} else if(
$randcard == 3){
$card '4';
} else if(
$randcard == 4){
$card '5';
} else if(
$randcard == 5){
$card '6';
} else if(
$randcard == 6){
$card '7';
} else if(
$randcard == 7){
$card '8';
} else if(
$randcard == 8){
$card '9';
} else if(
$randcard == 9){
$card '10';
}

$suit2 '';
$card2 '';

if(
$randsuit2 == 0){
$suit2 'clubs';
} else if(
$randsuit2 == 1){
$suit2 'diamonds';
} else if(
$randsuit2 == 2){
$suit2 'hearts';
} else if(
$randsuit2 == 3){
$suit2 'spades';
}

if(
$randcard2 == 10){
$card2 'j';
} else if(
$randcard2 == 11){
$card2 'q';
} else if(
$randcard2 == 12){
$card2 'k';
} else if(
$randcard2 == 0){
$card2 'a';
} else if(
$randcard2 == 1){
$card2 '2';
} else if(
$randcard2 == 2){
$card2 '3';
} else if(
$randcard2 == 3){
$card2 '4';
} else if(
$randcard2 == 4){
$card2 '5';
} else if(
$randcard2 == 5){
$card2 '6';
} else if(
$randcard2 == 6){
$card2 '7';
} else if(
$randcard2 == 7){
$card2 '8';
} else if(
$randcard2 == 8){
$card2 '9';
} else if(
$randcard2 == 9){
$card2 '10';
}

$suit3 '';
$card3 '';

if(
$randsuit3 == 0){
$suit3 'clubs';
} else if(
$randsuit3 == 1){
$suit3 'diamonds';
} else if(
$randsuit3 == 2){
$suit3 'hearts';
} else if(
$randsuit3 == 3){
$suit3 'spades';
}

if(
$randcard3 == 10){
$card3 'j';
} else if(
$randcard3 == 11){
$card3 'q';
} else if(
$randcard3 == 12){
$card3 'k';
} else if(
$randcard3 == 0){
$card3 'a';
} else if(
$randcard3 == 1){
$card3 '2';
} else if(
$randcard3 == 2){
$card3 '3';
} else if(
$randcard3 == 3){
$card3 '4';
} else if(
$randcard3 == 4){
$card3 '5';
} else if(
$randcard3 == 5){
$card3 '6';
} else if(
$randcard3 == 6){
$card3 '7';
} else if(
$randcard3 == 7){
$card3 '8';
} else if(
$randcard3 == 8){
$card3 '9';
} else if(
$randcard3 == 9){
$card3 '10';
}

$suit4 '';
$card4 '';

if(
$randsuit4 == 0){
$suit4 'clubs';
} else if(
$randsuit4 == 1){
$suit4 'diamonds';
} else if(
$randsuit4 == 2){
$suit4 'hearts';
} else if(
$randsuit4 == 3){
$suit4 'spades';
}

if(
$randcard4 == 10){
$card4 'j';
} else if(
$randcard4 == 11){
$card4 'q';
} else if(
$randcard4 == 12){
$card4 'k';
} else if(
$randcard4 == 0){
$card4 'a';
} else if(
$randcard4 == 1){
$card4 '2';
} else if(
$randcard4 == 2){
$card4 '3';
} else if(
$randcard4 == 3){
$card4 '4';
} else if(
$randcard4 == 4){
$card4 '5';
} else if(
$randcard4 == 5){
$card4 '6';
} else if(
$randcard4 == 6){
$card4 '7';
} else if(
$randcard4 == 7){
$card4 '8';
} else if(
$randcard4 == 8){
$card4 '9';
} else if(
$randcard4 == 9){
$card4 '10';
}

$suit5 '';
$card5 '';

if(
$randsuit5 == 0){
$suit5 'clubs';
} else if(
$randsuit5 == 1){
$suit5 'diamonds';
} else if(
$randsuit5 == 2){
$suit5 'hearts';
} else if(
$randsuit5 == 3){
$suit5 'spades';
}

if(
$randcard5 == 10){
$card5 'j';
} else if(
$randcard5 == 11){
$card5 'q';
} else if(
$randcard5 == 12){
$card5 'k';
} else if(
$randcard5 == 0){
$card5 'a';
} else if(
$randcard5 == 1){
$card5 '2';
} else if(
$randcard5 == 2){
$card5 '3';
} else if(
$randcard5 == 3){
$card5 '4';
} else if(
$randcard5 == 4){
$card5 '5';
} else if(
$randcard5 == 5){
$card5 '6';
} else if(
$randcard5 == 6){
$card5 '7';
} else if(
$randcard5 == 7){
$card5 '8';
} else if(
$randcard5 == 8){
$card5 '9';
} else if(
$randcard5 == 9){
$card5 '10';
}

$suit6 '';
$card6 '';

if(
$randsuit6 == 0){
$suit6 'clubs';
} else if(
$randsuit6 == 1){
$suit6 'diamonds';
} else if(
$randsuit6 == 2){
$suit6 'hearts';
} else if(
$randsuit6 == 3){
$suit6 'spades';
}

if(
$randcard6 == 10){
$card6 'j';
} else if(
$randcard6 == 11){
$card6 'q';
} else if(
$randcard6 == 12){
$card6 'k';
} else if(
$randcard6 == 0){
$card6 'a';
} else if(
$randcard6 == 1){
$card6 '2';
} else if(
$randcard6 == 2){
$card6 '3';
} else if(
$randcard6 == 3){
$card6 '4';
} else if(
$randcard6 == 4){
$card6 '5';
} else if(
$randcard6 == 5){
$card6 '6';
} else if(
$randcard6 == 6){
$card6 '7';
} else if(
$randcard6 == 7){
$card6 '8';
} else if(
$randcard6 == 8){
$card6 '9';
} else if(
$randcard6 == 9){
$card6 '10';
}

$suit7 '';
$card7 '';

if(
$randsuit7 == 0){
$suit7 'clubs';
} else if(
$randsuit7 == 1){
$suit7 'diamonds';
} else if(
$randsuit7 == 2){
$suit7 'hearts';
} else if(
$randsuit7 == 3){
$suit7 'spades';
}

if(
$randcard7 == 10){
$card7 'j';
} else if(
$randcard7 == 11){
$card7 'q';
} else if(
$randcard7 == 12){
$card7 'k';
} else if(
$randcard7 == 0){
$card7 'a';
} else if(
$randcard7 == 1){
$card7 '2';
} else if(
$randcard7 == 2){
$card7 '3';
} else if(
$randcard7 == 3){
$card7 '4';
} else if(
$randcard7 == 4){
$card7 '5';
} else if(
$randcard7 == 5){
$card7 '6';
} else if(
$randcard7 == 6){
$card7 '7';
} else if(
$randcard7 == 7){
$card7 '8';
} else if(
$randcard7 == 8){
$card7 '9';
} else if(
$randcard7 == 9){
$card7 '10';
}
?>

<table border='3'>
<tr>
<td style="text-align: center; font-weight:bold;"><? echo $cards[$randcard];
echo 
" of ";
echo 
$suits[$randsuit]; ?></td>
<td style="text-align: center; font-weight:bold;"><? echo $cards[$randcard2];
echo 
" of ";
echo 
$suits[$randsuit2]; ?></td>
<td style="text-align: center; font-weight:bold;"><? echo $cards[$randcard3];
echo 
" of ";
echo 
$suits[$randsuit3]; ?></td>
<td style="text-align: center; font-weight:bold;"><? echo $cards[$randcard4];
echo 
" of ";
echo 
$suits[$randsuit4]; ?></td>
<td style="text-align: center; font-weight:bold;"><? echo $cards[$randcard5];
echo 
" of ";
echo 
$suits[$randsuit5]; ?></td>
<td style="text-align: center; font-weight:bold;"><? echo $cards[$randcard6];
echo 
" of ";
echo 
$suits[$randsuit6]; ?></td>
<td style="text-align: center; font-weight:bold;"><? echo $cards[$randcard7];
echo 
" of ";
echo 
$suits[$randsuit7]; ?></td>
</tr>
<tr>
<td><? echo "<img src='images/".$suit."-".$card."-150.png' />"?></td>
<td><? echo "<img src='images/".$suit2."-".$card2."-150.png' />"?></td>
<td><? echo "<img src='images/".$suit3."-".$card3."-150.png' />"?></td>
<td><? echo "<img src='images/".$suit4."-".$card4."-150.png' />"?></td>
<td><? echo "<img src='images/".$suit5."-".$card5."-150.png' />"?></td>
<td><? echo "<img src='images/".$suit6."-".$card6."-150.png' />"?></td>
<td><? echo "<img src='images/".$suit7."-".$card7."-150.png' />"?></td>
</tr>
</table>

</body>
</html>

.

felgall 06-27-2012 03:15 AM

It is a bit hard to comment on the code as you didn't include it in your post.

skill3d 06-27-2012 03:19 AM

Quote:

Originally Posted by felgall (Post 1245409)
It is a bit hard to comment on the code as you didn't include it in your post.


There is a download link, it's under 1mb, However. I've included the rough code.

felgall 06-27-2012 03:29 AM

You don't appear to have anything there that prevents the same card being selec ted more than once.

An easier way might be to set up an array of values representing all 52 cards then use the shuffle function to arrange them in random order then just return the first seven entries in the array.

jdswebservice 07-14-2012 02:18 AM

This code would be MUCH easier done with switch statements. I'll actually take a crack at this and post what i get. :D This might be fun!

J-

jdswebservice 07-14-2012 03:21 AM

Rough Draft
 
So far i have this. This is the basics with no images. Code is MUCH shorter, and much more precise. :D Hope you dont mind me stealing the idea!

PHP Code:

<?php
    
//images are in format of: 
    //#x.gif
    //Where # is card value
    //Where "x" is card suit
    
    //clubs = c
    //diamonds = d
    //hearts = h
    //spades = s
    

    //Select 7 cards with the for loop.
    
for( $i 1$i <= 7$i++ ) {
        
//select card, define suit as numeric value
        
$card["card" $i]['suit_num'] = rand(0,3);
        
//select card, define card itself as numeric value
        
$card["card" $i]['card_num'] = rand(1,13);
        
//redefine card's suit as character value assigning either c, d, h, or s
        //This is used for image filepath
        
switch ($card["card" $i]['suit_num']) {
            case 
0:
                
$card["card" $i]['suit_char'] = "c";
                
$card["card" $i]['suit_str'] = "Clubs";
                break;
            case 
1:
                
$card["card" $i]['suit_char'] = "d";
                
$card["card" $i]['suit_str'] = "Diamonds";
                break;
            case 
2:
                
$card["card" $i]['suit_char'] = "h";
                
$card["card" $i]['suit_str'] = "Hearts";
                break;
            case 
3:
                
$card["card" $i]['suit_char'] = "s";
                
$card["card" $i]['suit_str'] = "Spades";
                break;
        }
        
//define card filepath and store in "card_img"
        
$card["card" $i]['card_img'] = "cards/" $card["card" $i]['card_num'] . $card["card" $i]['suit_char'] . ".gif";
        
//Define the Card in the form of words.
        
switch($card["card" $i]['card_num']) {
            case 
1
                
$card["card" $i]['card_str'] = "Ace of ";
                break;
            case 
2
                
$card["card" $i]['card_str'] = "Two of ";
                break;
            case 
3
                
$card["card" $i]['card_str'] = "Three of ";
                break;
            case 
4
                
$card["card" $i]['card_str'] = "Four of ";
                break;
            case 
5
                
$card["card" $i]['card_str'] = "Five of ";
                break;
            case 
6
                
$card["card" $i]['card_str'] = "Six of ";
                break;
            case 
7
                
$card["card" $i]['card_str'] = "Seven of ";
                break;
            case 
8
                
$card["card" $i]['card_str'] = "Eight of ";
                break;
            case 
9
                
$card["card" $i]['card_str'] = "Nine of ";
                break;
            case 
10
                
$card["card" $i]['card_str'] = "Ten of ";
                break;
            case 
11
                
$card["card" $i]['card_str'] = "Jack of ";
                break;
            case 
12
                
$card["card" $i]['card_str'] = "Queen of ";
                break;
            case 
13
                
$card["card" $i]['card_str'] = "King of ";
                break;
        }
        
//Combine card_str and suit_str into one for the table headers
        
$card["card" $i]['card_info'] = $card["card" $i]['card_str'] . $card["card" $i]['suit_str'];
    }
    





    
//display card
    
for($i 1$i <= 13$i++ ) {
        echo(
$card["card" $i]['card_info'] . "<br>" $card["card" $i]['card_img'] . "<br><br>");
    }
    
?>
<html>
<head>
    <title>
        Coding Forums Post 266395: Card Generator
    </title>
</head>
<body>


</body>
</html>


jdswebservice 07-14-2012 03:41 AM

Semi-Final Draft
 
FULLY FUNCTIONAL script!

Css file is below as well.

cards are at: http://logicaldevelopment.net/codingforums/cards.zip

I will be making a script to show the last 5 hands as well. :) This should help show the randomness (Or lack there of) of the hands.


index.css
Code:

body {
        text-align: center;
        background-color: #000000;
        color: #ffffff;
}
table {
        margin-left: auto;
        margin-right: auto;
}
th, td {
        text-align: center;
        width: 150px;
        border: 1px dashed #ffffff;
}

index.php
PHP Code:

<?php
    
//images are in format of: 
    //#x.gif
    //Where # is card value
    //Where "x" is card suit
    
    //clubs = c
    //diamonds = d
    //hearts = h
    //spades = s
    
    //Select 7 cards with the for loop.
    
for( $i 1$i <= 7$i++ ) {
        
//select card, define suit as numeric value
        
$card["card" $i]['suit_num'] = rand(0,3);
        
//select card, define card itself as numeric value
        
$card["card" $i]['card_num'] = rand(1,13);
        
//redefine card's suit as character value assigning either c, d, h, or s
        //This is used for image filepath
        
switch ($card["card" $i]['suit_num']) {
            case 
0:
                
$card["card" $i]['suit_char'] = "c";
                
$card["card" $i]['suit_str'] = "Clubs";
                break;
            case 
1:
                
$card["card" $i]['suit_char'] = "d";
                
$card["card" $i]['suit_str'] = "Diamonds";
                break;
            case 
2:
                
$card["card" $i]['suit_char'] = "h";
                
$card["card" $i]['suit_str'] = "Hearts";
                break;
            case 
3:
                
$card["card" $i]['suit_char'] = "s";
                
$card["card" $i]['suit_str'] = "Spades";
                break;
        }
        
//define card filepath and store in "card_img"
        
$card["card" $i]['card_img'] = "cards/" $card["card" $i]['card_num'] . $card["card" $i]['suit_char'] . ".gif";
        
//Define the Card Itself in the form of words.
        
switch($card["card" $i]['card_num']) {
            case 
1
                
$card["card" $i]['card_str'] = "Ace of ";
                break;
            case 
2
                
$card["card" $i]['card_str'] = "Two of ";
                break;
            case 
3
                
$card["card" $i]['card_str'] = "Three of ";
                break;
            case 
4
                
$card["card" $i]['card_str'] = "Four of ";
                break;
            case 
5
                
$card["card" $i]['card_str'] = "Five of ";
                break;
            case 
6
                
$card["card" $i]['card_str'] = "Six of ";
                break;
            case 
7
                
$card["card" $i]['card_str'] = "Seven of ";
                break;
            case 
8
                
$card["card" $i]['card_str'] = "Eight of ";
                break;
            case 
9
                
$card["card" $i]['card_str'] = "Nine of ";
                break;
            case 
10
                
$card["card" $i]['card_str'] = "Ten of ";
                break;
            case 
11
                
$card["card" $i]['card_str'] = "Jack of ";
                break;
            case 
12
                
$card["card" $i]['card_str'] = "Queen of ";
                break;
            case 
13
                
$card["card" $i]['card_str'] = "King of ";
                break;
        }
        
//Combine card_str and suit_str into one for the table headers
        
$card["card" $i]['card_info'] = $card["card" $i]['card_str'] . $card["card" $i]['suit_str'];
        
    }    
?>
<html>
<head>
    <title>
        Coding Forums Post 266395: Card Generator
    </title>
    <link rel="stylesheet" type="text/css" href="index.css" />
</head>
<body>
    <input type="submit" value="Pick a New Hand!" onclick="javascript:location.reload(true)" />
    <br>
    <br>
    <table id="card_table">
        <tr>
            <?php
                
//display card
                
for($i 1$i <= 7$i++ ) {
                    echo(
"<th>" $card["card" $i]['card_info'] . "</th>");
                }
            
?>
        </tr>
        <tr>
            <?php
                
//display card
                
for($i 1$i <= 7$i++ ) {
                    echo(
"<td><img src=\"" $card["card" $i]['card_img'] . "\" /></td>");
                }
            
?>
        </tr>

    </table>
</body>
</html>


jdswebservice 07-14-2012 05:00 AM

Finally done!!!!!
 
It's FINALLY done! :D

So now this site has the following functionality!
  • When page is refreshed, generates new hand
  • Records hand
  • displays hand in "text" view below, as well as the previous 4 hands
  • Stores hand in old_hands.php
  • deletes entries after line 46 and keeps ONLY 5 entries in old_hands.php

All the code is commented out for you to read. If you have any questions let me know via PM as i will NOT be subscribing to this page and will probably be the last time i ever come to this page.

Hopefully you like what you see!

Code is below and can also be found here:

Virus Analysis of File per https://VirusTotal.com/

http://logicaldevelopment.net/codingforums/266395.zip

Make sure if you do NOT download my zip file, that you create a new file called old_hands.php and leave it BLANK! dont even open it with a text editor! lol

Please donate to me if you use this script! it did take some time to make! :D Help a fellow coder out!
Thanks!

https://www.paypalobjects.com/en_US/..._donate_SM.gif


index.php
PHP Code:

<?php
    
//images are in format of: 
    //#x.gif
    //Where # is card value
    //Where "x" is card suit
    
    //clubs = c
    //diamonds = d
    //hearts = h
    //spades = s
    
    //Select 7 cards with the for loop.
    
for( $i 1$i <= 7$i++ ) {
        
//select card, define suit as numeric value
        
$card["card" $i]['suit_num'] = rand(0,3);
        
//select card, define card itself as numeric value
        
$card["card" $i]['card_num'] = rand(1,13);
        
//redefine card's suit as character value assigning either c, d, h, or s
        //This is used for image filepath
        
switch ($card["card" $i]['suit_num']) {
            case 
0:
                
$card["card" $i]['suit_char'] = "c";
                
$card["card" $i]['suit_str'] = "Clubs";
                break;
            case 
1:
                
$card["card" $i]['suit_char'] = "d";
                
$card["card" $i]['suit_str'] = "Diamonds";
                break;
            case 
2:
                
$card["card" $i]['suit_char'] = "h";
                
$card["card" $i]['suit_str'] = "Hearts";
                break;
            case 
3:
                
$card["card" $i]['suit_char'] = "s";
                
$card["card" $i]['suit_str'] = "Spades";
                break;
        }
        
//define card filepath and store in "card_img"
        
$card["card" $i]['card_img'] = "cards/" $card["card" $i]['card_num'] . $card["card" $i]['suit_char'] . ".gif";
        
//Define the Card Itself in the form of words.
        
switch($card["card" $i]['card_num']) {
            case 
1
                
$card["card" $i]['card_str'] = "Ace of ";
                break;
            case 
2
                
$card["card" $i]['card_str'] = "Two of ";
                break;
            case 
3
                
$card["card" $i]['card_str'] = "Three of ";
                break;
            case 
4
                
$card["card" $i]['card_str'] = "Four of ";
                break;
            case 
5
                
$card["card" $i]['card_str'] = "Five of ";
                break;
            case 
6
                
$card["card" $i]['card_str'] = "Six of ";
                break;
            case 
7
                
$card["card" $i]['card_str'] = "Seven of ";
                break;
            case 
8
                
$card["card" $i]['card_str'] = "Eight of ";
                break;
            case 
9
                
$card["card" $i]['card_str'] = "Nine of ";
                break;
            case 
10
                
$card["card" $i]['card_str'] = "Ten of ";
                break;
            case 
11
                
$card["card" $i]['card_str'] = "Jack of ";
                break;
            case 
12
                
$card["card" $i]['card_str'] = "Queen of ";
                break;
            case 
13
                
$card["card" $i]['card_str'] = "King of ";
                break;
        }
        
//Combine card_str and suit_str into one for the table headers
        
$card["card" $i]['card_info'] = $card["card" $i]['card_str'] . $card["card" $i]['suit_str'];
    }
    
//save old hand to file    
    //Open File
    
$myFile "old_hands.php";
    
$lines file($myFile);
    
$fh fopen($myFile'w+') or die("can't open file");
    
//add changes to new variable
    
$changes "";
    for(
$i 1$i <= 7$i++) {
        
$changes .= "Card " $i ": " $card["card" $i]['card_info'] . "<br>\n";
    }    
    
$changes $changes "<br>\n<br>\n";
    
//write changes to new file
    
fwrite($fh$changes);
    foreach (
$lines as $line) { fwrite$fh"$line"); }
    
//define from what line ONWARD/DOWN to delete
    
$lineNum 46;
    
//Delete Lines Function
    
function delLineFromFile($fileName$lineNum){
        
//Delete 10 lines (One entry) 1 line at a time
        
for($i 1$i <= 10$i++) {
            
// read the file into an array    
            
$arr file($fileName);
            
// the line to delete is the line number minus 1, because arrays begin at zero
            
$lineToDelete $lineNum-1;
            
//remove the line
            
unset($arr["$lineToDelete"]);
            
// open the file for reading
            
$fp fopen($fileName'w+');
            
// write the array to the file
            
foreach($arr as $line) { fwrite($fp,$line); }
        }
    }
    
//we dont want any more then 5 entries to delet the last/6th entry
    
delLineFromFile($myFile$lineNum);
    
//Only display lines you specify function
    
function sumarize($your_string$limit_lines){
       
$count 0;
       foreach(
explode("\n"$your_string) as $line){
           
$count++;
           echo 
$line."\n";
           if (
$count == $limit_lines) break;        
       }
    }

?>
<html>
<head>
    <title>
        Coding Forums Post 266395: Card Generator
    </title>
    <link rel="stylesheet" type="text/css" href="index.css" />
</head>
<body>
    <input type="submit" value="Pick a New Hand!" onclick="javascript:location.reload(true)" />
    <br>
    <br>
    <table id="card_table">
        <tr>
            <?php
                
//display card information in table headers
                
for($i 1$i <= 7$i++ ) {
                    echo(
"<th>" $card["card" $i]['card_info'] . "</th>");
                }
            
?>
        </tr>
        <tr>
            <?php
                
//display cards
                
for($i 1$i <= 7$i++ ) {
                    echo(
"<td class=\"card_img\"><img src=\"" $card["card" $i]['card_img'] . "\" /></td>");
                }
            
?>
        </tr>
        <tr>
            <td colspan="7" id="old_hands">
                <span class="header">All hands displayed below are in order from most recent to less recent.</span>
                <br>
                <br>
                <?php
                    
//Only display lines 1-43 as we dont want to display the last two lines as they are <br> tags
                    
echo(sumarize(file_get_contents($myFile), 43)); 
                
?>
            </td>
        </tr>
    </table>
</body>
</html>
<?php
fclose
($fh);
?>

index.css
Code:

body {
        text-align: center;
        background-color: #000000;
        color: #ffffff;
}
table {
        margin-left: auto;
        margin-right: auto;
}
th, .card_img {
        text-align: center;
        width: 150px;
        border: 1px dashed #ffffff;
        font: 10pt normal Tahoma, Arial, sans serif;
}
#old_hands {
        text-align: left;
        border: 1px dashed #ffffff;
        padding: 10px;
}
.header {
        font: 13pt normal Tahoma, Arial, sans serif;
}



All times are GMT +1. The time now is 10:46 PM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.