[Solved] Please show me a better way

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Hibba
Forum Commoner
Posts: 58
Joined: Fri Oct 29, 2004 11:37 pm

[Solved] Please show me a better way

Post 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!
Last edited by Hibba on Wed Dec 22, 2004 10:47 pm, edited 1 time in total.
rehfeld
Forum Regular
Posts: 741
Joined: Mon Oct 18, 2004 8:14 pm

Post 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;



?>
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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";
Post Reply