The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Php and html inside a php array
Discuss Php and html inside a php array in the PHP Development forum on Dev Shed. Php and html inside a php array PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 3rd, 2013, 03:33 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 25
Time spent in forums: 8 h 36 m 44 sec
Reputation 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];
}
?>
|

January 3rd, 2013, 04:09 AM
|
 |
Known to taste like chicken
|
|
Join Date: Aug 2003
Location: In front of my computer
|
|
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?
|

January 3rd, 2013, 04:33 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
|
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.
|

January 3rd, 2013, 06:29 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 25
Time spent in forums: 8 h 36 m 44 sec
Reputation 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?
|

January 3rd, 2013, 06:58 AM
|
 |
pollyanna
|
|
Join Date: Jul 2012
Location: Germany
|
|
Quote: | Originally Posted by chrismarsden how can i strip these? |
Um, by leaving them out? Each \" yields a double quote in your output.
|

January 3rd, 2013, 07:38 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 25
Time spent in forums: 8 h 36 m 44 sec
Reputation Power: 0
|
|
|
its always the simple answers that escape me lol
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|