Page 1 of 1

[Solved] Please show me a better way

Posted: Thu Dec 16, 2004 10:19 pm
by Hibba
What is a beter way to do this (ie. some kind of include, without breaking up all the code):

Code: Select all

<?php
$body = 'Name: ' . $name;
	$body .= '<br>E-mail: ' . $email;
	$body .= '<br>Amount: ' .$amount;
	$body .= '<br><div align="left"><p>Direct money to:<br>';
	$body .= 'Chapel?: ' . $chapel;
	$body .= '<br>Scholarship: ' . $scholarship;
	$body .= '<br>In ' . $selectName . ' of:' . $choose_name;
	$body .= '<br>Membership? ' . $membership;
	$body .= '<br>As Needed? ' . $as_needed;
	$body .= '<br>Work Weekend? ' . $work_week;
	$body .= '<br>Other? ' . $other . 'What? ' . $other_name;
	$body .= '</p></div>';
?>
Thanks!

Posted: Thu Dec 16, 2004 11:55 pm
by rehfeld

Code: Select all

<?php

$body = '
you can span multiple'.$lines.'

you can span multiple'.$lines.'


you can span multiple'.$lines.'


';




$body = "

you can also use $double $quotes

you can also use $double $quotes

you can also use $double $quotes

";


$body = <<<FOO

you can also use "heredoc syntax"
.....'''''"""""
quotes dont need to be escaped, and
$variables will be expanded properly.
however it is a tiny bit slower.

my advice will cost you $20 dollars
(notice that a $ followed by a number didnt give an error)


FOO;



?>

Posted: Fri Dec 17, 2004 7:26 am
by timvw
in that case my code would fill up :


$show = array();
$show[] = array('label' => 'E-mail', 'value' => $email);
$show[] = array('label' => 'Amount', 'value' => $amount);

and then when i start displaying retrieved data:

foreach($show as $label => $value)
echo "<br>$label: $value";