Possible Duplicate:
Why does PHP echo'd text lose it's formatting?
I cant get the new line to function work right. It just comes out as one line. Like this -
Make: Sony Model: a Processor: Intel Core 2 Duo
This is the code for it ---
$message="Make: " . $_POST['make'] . "\r\n Model: " . $_POST['model'] . "\r\n Processor: " . $_POST['processor'];
When this is sent as an email it works perfect but when i do
echo $message;
it just comes out as the above - it all on one line. How can i make this work?
thankyou
You are presumably echoing this onto a web page.
Browsers do not (or at least, should not) respect literal new lines, you have to use the HTML <br>
tag instead.
Try this:
echo str_replace(array("\r\n","\r","\n"),'<br>',$message);
// or
echo nl2br($message);
HTML ignores newlines.
Instead, you should use <br />
, <pre>
, or <table>
.
If you want print it using HTML you'll either need to use <br />
or use the nl2br()
function.
Using <br />
:
$message = 'Make: ' . $_POST['name'] . '<br />'; //...
If you want to send plaintext, set an appropriate HTTP header, e.g.
header('Content-Type: text/plain');
Most browsers will take this as a hint to display it in 'raw mode'.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With