Avatar of adande11
adande11
 asked on

How do I implement a carriage return in a php script?

I currently am using the following php code to prepare a message for an email:

$message = "$First_Name,$Email_Address,$attn \n";

The format of the output it produces is: Paul,paul@myb.com,Teacher

I now need the output in this format (ie. two carriage returns after each piece of data and labels before each piece of data:
first  name = Darius

email =  Darius@myb.com

Profession  = Tech Buff

How do I implement a carriage return in a php script?
PHP

Avatar of undefined
Last Comment
adande11

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
darron_chapman

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Xyptilon2

Assuming that a , can be used as a delimiter

list ($First_Name,$Email_Address,$attn) = split(",",$message);

$msg = "first  name = " . $First_Name . "\n\n";
$msg .= "email =  " . $Email_Address . "\n\n";
$msg .= "Profession  = " . $attn . "\n\n";

$msg now contains your output
SOLUTION
harrrrpo

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
adande11

ASKER
kudos darron chapman!  Your code worked, except for a minor change.  I had to add a space after the equal sign as shown here: $message= "first name...

Question:  what does the \r\n do that harrrrpo mentioned?

Can someone explain Xyptilon2's solution please?  I don't quite get it.

Thanks to all of you experts!
harrrrpo

\r\n is a line separator
in some  mail servers like google u will need '\r\n' as separator instead of '\n' only
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
adande11

ASKER
Can someone explain Xyptilon2's solution please?  I don't quite get it.
harrrrpo

the same as darron_chapman but he assumes that like email.... are in a varaible $message and separated by `,`
SOLUTION
Xyptilon2

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
adande11

ASKER
Thanks all.  I am upping the points on this one!
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
darron_chapman

Thanks!
adande11

ASKER
This is the solution I used in the end.  i had to add a space after the $message= as seen below.

$message= "first name = $First_Name\n\nemail =  $Email_Address\n\nProfession  = $attn \n";