mega77 Posted December 17, 2007 Share Posted December 17, 2007 I would like to know which is the correct way of formatting a mail message. $message = "text"; // should the first "$message" be with an equals sign or with a ".=" ? $message .= "text $variable"; // is mixing text and variables inside quotes "correct" ? $message .= "text $variable\n"; // should the "\n" be inside the quotes or outside like: $message .= "text $variable" . "\n"; None of these ways result in notices or errors that I know of. Even by setting php to: error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
Grego Posted December 17, 2007 Share Posted December 17, 2007 $message = "text"; // should the first "$message" be with an equals sign or with a ".=" ? $message .= "text $variable"; // is mixing text and variables inside quotes "correct" ? $message .= "text $variable\n"; // should the "\n" be inside the quotes or outside like: $message .= "text $variable" . "\n"; 1) You're right the way you've shown it. You can't use .= as the variable $message hasn't been defined yet. .= adds to the end of a variable but it can't add to the end if nothing exists there yet => $message="text" 2) To add variables, you should use "$message .= 'text ' . $variable" Again, the . adds to the previous string, so if $variable='ruin' then $message="texttext ruin" 3) New lines should go inside the quotes, yes. So $message="texttext ruintext ruin " =P I was wrong about the second point, it seems. Look at the next post =) Quote Link to comment Share on other sites More sharing options...
trq Posted December 17, 2007 Share Posted December 17, 2007 Yes it is correct. 1: = is an assignment operator while .= concatinates two string together. So yes, when you first create $message it only needs = 2: Variables can quite happilly be used within double quotes. 3: The \n newline char meens nothing outside of double quotes and will in fact generate an error. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.