#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    25
    Rep Power
    0

    Php and html inside a php array


    Hi guys,

    tried to google for this problem but cant seem to find the right answer.

    I have a PHP array which i want to place html inside of, this html also has to php echos to get variables set by the database.

    I can get the html to output perfectly fine, the php however comes up as text inside that.

    any ideas or solutions welcome.

    PHP Code:
    <?php
    $html 
    = array
    (
    '<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
    <input type="hidden" name="cmd" value="_s-xclick">
    <input type="hidden" name="hosted_button_id" value="T9AKEUD6E">
    <table>
    <tr><td><input type="hidden" name="on0" value="Morgan Knightley Referance Num">Morgan Knightley Referance Number</td></tr><tr><td><input type="text" name="os0" maxlength="200"  value="<?php echo $MKREF.""; ?>"></td></tr>
    <tr><td><input type="hidden" name="on1" value="SiP Referance Number">SiP Referance Number</td></tr><tr><td><input type="text" name="os1" maxlength="200"  value="<?php echo $row[1]; ?>"></td></tr>
    </table>
    <input type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_paynow_LG.gif" border="0" name="submit" alt="PayPal  The safer, easier way to pay online."></form>' 
    '75 pound box goes here when problem fixed');
    ?>
            <?php
    if ( $row[3] = "50.00" ) {
        echo 
    $html[0];
    } else {
        echo 
    $html[1];
    }        
    ?>
  2. #2
  3. Known to taste like chicken
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Location
    In front of my computer
    Posts
    399
    Rep Power
    312
    php's eval construct might be what you want, BUT, it comes with a some risks.

    You could also flesh out your string before you store it in the array, or look into another way of doing it.

    I would skip the array all together unless you absolutely positively have to have it, and just form the data if / when it is needed:

    PHP Code:
    <?php 
    if ( $row[3] = "50.00" ) { 
        echo 
    "<form action...value=\"".$MKREF."\"></td>...value=\"".$row[1]."\"></td>...</form>"
    } else { 
        echo 
    "75 pound etc etc..."
    }         
    ?>
    that way you're only ever dealing with data you're going to use, and not processing variables which will never impact on the output etc.
    "Take thy beak from out my heart, and take thy form from off my door" - Homer J Simpson / Edgar Allan Poe

    Looking for a project Idea?
  4. #3
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Hi,

    what exactly are you trying to do with the array? This approach looks very obscure (as sir_drinxalot already said), and I'm pretty sure there's a sane solution for the original problem.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    25
    Rep Power
    0
    basicly i was after checking an amount in the database, based on this amount output 1 of 2 payment option buttons.

    I have now fixed my original problem with a helping hand from the post sir_drinxalot made.

    PHP Code:
    <?php
    if ( $row[3] >= "50.00" ) {
        echo 
    "Thank you   <b>\"".$row[0]."\",</b> <br>
            You have chosen to pay for your ticket and qualify for the discount, this is related to your car registration number: <b>\""
    .$row[2]."\"</b><br><br>
            <b>Details of Offence</b><br>
            Offence Date: \""
    .date("d/m/Y"strtotime $row[8] ) )."\"<br>
            Offence Time: \""
    .$row[9]."\"<br>
            Offence Committed: \""
    .$row[7]."\"<br>
            <b>Your Details</b><br>
            Your Address:\""
    .$row[4]."\",\"".$row[5]."\",\"".$row[6]."\"<br><br>
        <br></p>"
    ;
    } else {
        echo         
    "<b></b>";
    }        
    ?>
    now the problem im getting is this. the output information appears as "persons name" with the "" surrounding all the database text.

    how can i strip these?
  8. #5
  9. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    Originally Posted by chrismarsden
    how can i strip these?
    Um, by leaving them out? Each \" yields a double quote in your output.
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    25
    Rep Power
    0
    its always the simple answers that escape me lol

IMN logo majestic logo threadwatch logo seochat tools logo