/    Sign up×
Community /Pin to ProfileBookmark

How to input a large block of html code with passed variables?

How to input a large block of html code with passed variables?

Hi all

I have a large block of html code that is part of the paypal add to cart button.

I need to add this code a number of times with different variables for each one.

I want to have this block of html in a separate function that I can then call and pass in the variables in.

PHP

[code]
<?php
function item($name, $number){
echo ”
<div class=’product’>
<h2>Product Name</h2>
<form target=’paypal’ action=’https://www.paypal.com/cgi-bin/webscr’ method=’post’>
<input type=’hidden’ name=’cmd’ value=’_cart”>
<input type=’hidden’ name=’business’ value=’emailAddress’>
<input type=’hidden’ name=’lc’ value=’GB’>
<input type=’hidden’ name=’item_name’ value='”.$name.”‘>
<input type=’hidden’ name=’item_number’ value='”.$number.”‘>
<input type=’hidden’ name=’button_subtype’ value=’products’>
<input type=’hidden’ name=’no_note’ value=’0′>
<input type=’hidden’ name=’cn’ value=’Add special instructions to the seller’>
<input type=’hidden’ name=’no_shipping’ value=’2′>
<input type=’hidden’ name=’add’ value=’1′>
<input type=’hidden’ name=’bn’ value=’PP-ShopCartBF:btn_cart_LG.gif:NonHosted’>
<table>
<tr><td><input type=’hidden’ name=’on0′ value=’Number of Users’>Number of Users</td></tr><tr><td><select name=’os0′>
<option value=’1 – 5′>1 – 5 £0.01</option>
<option value=’6 – 10′>6 – 10 £0.02</option>
<option value=’11 – 20′>11 – 20 £0.03</option>
<option value=’21 – 50′>21 – 50 £0.04</option>
<option value=’51 – 100′>51 – 100 £0.05</option>
<option value=’100+’>100+ £0.06</option>
</select> </td></tr>
</table>
<input type=’hidden’ name=’currency_code’ value=’GBP’>
<input type=’hidden’ name=’option_select0′ value=’1 – 5′>
<input type=’hidden’ name=’option_amount0′ value=’0.01′>
<input type=’hidden’ name=’option_select1′ value=’6 – 10′>
<input type=’hidden’ name=’option_amount1′ value=’0.02′>
<input type=’hidden’ name=’option_select2′ value=’11 – 20′>
<input type=’hidden’ name=’option_amount2′ value=’0.03′>
<input type=’hidden’ name=’option_select3′ value=’21 – 50′>
<input type=’hidden’ name=’option_amount3′ value=’0.04′>
<input type=’hidden’ name=’option_select4′ value=’51 – 100′>
<input type=’hidden’ name=’option_amount4′ value=’0.05′>
<input type=’hidden’ name=’option_select5′ value=’100+’>
<input type=’hidden’ name=’option_amount5′ value=’0.06′>
<input type=’hidden’ name=’option_index’ value=’0′>
<input class=’button’ type=’image’ src=’https://www.paypalobjects.com/en_GB/i/btn/btn_cart_LG.gif’ border=’0′ name=’submit’ alt=’PayPal — The safer, easier way to pay online.’>
<img alt=” border=’0′ src=’https://www.paypalobjects.com/en_GB/i/scr/pixel.gif’ width=’1′ height=’1′>
</form>
</div>

}

?>

[/code]

HTML

[code]
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>

<html xmlns=”http://www.w3.org/1999/xhtml” xml:lang=”en” lang=”en”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″/>

<title>untitled</title>

<?php

require_once(“functions.php”);

?>

</head>

<body>

<?php

item($car, $deo);

?>

</body>
</html>
[/code]

How can I output this html code from a function with passed in variables ?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@tracknutNov 28.2011 — Other than changing the last few lines in your function definition to:
<i>
</i> ";
}
?&gt;

it all looks about right to me.

Dave
Copy linkTweet thisAlerts:
@NogDogNov 28.2011 — I'm not 100&#37; sure what you're asking, but if you have the function return() the string instead of echo()-ing it, it might then be more re-usable in multiple situations. (In the view you would then echo the function call if that's what you want to happen at that point.)
×

Success!

Help @ttmt spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...