Need a little assistance with those Pesky Control Characters

I’m saving input from a text field into my database, and then also using it in the body of an outgoing email. Database part seems working fine.

First, I process my string:
[php]$add_details = trim($_POST[‘add_details’]);
$add_details=mysql_real_escape_string($add_details);[/php]

Info gets inserted into the database as:
[php]’$add_details’[/php]

So far so good. Here’s where I’m having a problem.
Output into an email body, but the outputted text is showing the control characters.

Code I’m using:
[php]$MESSAGE_BODY .= "\n\n

Additional Details:$add_details

;}[/php]

But the output looks like:
[php]THIS IS A TEST\r\n\r\nThanks,\r\nBen[/php]

Still green around the ears PHP noob. Not sure what I need to do to eliminate the control characters in the output there.

Thanks

Are you sending it as html email?

Yes

[php]$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;[/php]

Should have included more of the code - sorry!

[php]$headers = ‘MIME-Version: 1.0’ . “\r\n”;
$headers .= ‘Content-type: text/html; charset=iso-8859-1’ . “\r\n”;
$headers .= “From: somebody@somewhere…com\r\n”;
$headers .= ‘Bcc: [email protected]’ . “\r\n”;

// Mail it
mail($to, $subject, $MESSAGE_BODY, $headers);[/php]

I supposed I could do something like this:

[php]$add_details = str_replace(array("\r\n", “\r”, “\n”), “
”, $add_details);
$MESSAGE_BODY .= "\n\n

Additional Details:
$add_details

[/php]

But that doesn’t cure the problem of why they want to display to start with…

I’m assuming the database text you are entering to the database is a multi-line text so it will have newlines etc automatically. What you wan’t to do after this is:
[php]
$MESSAGE_BOST .=“

Additional Details:
”.nl2br($add_details)."

";[/php]

nl2br will replace any new line control characters with
automatically so you don’t have to actually touch the control characters yourself.

Sponsor our Newsletter | Privacy Policy | Terms of Service