True however K.I.S.S would say , if you can use it like
echo “This is a statement {$Blah}.”; echo “This is also a statement {$objBlah->BlahString}.”; echo “This is also a statement {$tBlah[‘BlahKey’]}.”; You should do it so you are always using the same expected format, cleaner for readability and training other people to understand how you code. This is my personal thoughts on it, everyone has their own prefs. David From: Ashley Sheridan [mailto:a...@ashleysheridan.co.uk] Sent: Wednesday, October 21, 2009 3:43 PM To: David Murphy Cc: php-general@lists.php.net Subject: RE: [PHP] how call a variable in a text On Wed, 2009-10-21 at 15:40 -0500, David Murphy wrote: This is actually much better the { and } make it very obvious where the variable is and also it can keep odd issues from occurring sometimes. $message="<b> There is a text {$variable} trial. </b> "; There is always sprint type functions also. David -----Original Message----- From: Andrew Ballard [mailto:aball...@gmail.com] Sent: Wednesday, October 21, 2009 3:23 PM To: Bulend Kolay Cc: php-general@lists.php.net Subject: Re: [PHP] how call a variable in a text 2009/10/21 Bulend Kolay <bma...@ihlas.net.tr>: > I 'll send a mail in html form using php5. > > cat send.php > <?php > $variable="date1" ; > .. > .. > $message=' > > <b> There is a text $variable trial. </b> '; > > mail($to, $subject, $message, $headers) ; ?> > > when I run send.php, I get the mail. But I can't call variable called > variable. it comes as string. > How can I correct this? > You need to use double quotes (or HEREDOC) if you want PHP to replace $variable with its value in the string: $message=" <b> There is a text $variable trial. </b> "; or $message = <<<MESSAGE <b> There is a text $variable trial. </b> MESSAGE; Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php No virus found in this outgoing message. Checked by AVG - www.avg.com Version: 8.5.423 / Virus Database: 270.14.24/2449 - Release Date: 10/20/09 18:42:00 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php The {} only become really useful when you're trying to reference arrays within a string: $var = array('great', 'boring'); $text = "this is {$var[0]}."; Without the curly braces, PHP wouldn't be able to figure out whether you wanted the end string to be 'This is great.' or 'This is [0].' despite the variable itself clearly being an array. Thanks, Ash http://www.ashleysheridan.co.uk
No virus found in this outgoing message. Checked by AVG - www.avg.com Version: 8.5.423 / Virus Database: 270.14.24/2449 - Release Date: 10/20/09 18:42:00
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php