I have created a simple wall post feature, like on FaceBook.
A user writes a post, the post is submitted to the database and then echoed back onto the website; that all
The answer(s) suggesting nl2br are great, I would go with that approach.
In your original question I think there is some confusion -- users don't type \n
every time they want a new line. The slash is for escaping (special character, not a normal n).
On Windows machines, the Enter key is equivalent to \r\n
where \r
is carriage return and \n
is new line. On Linux or similar, the Enter key is \n
. \r
's ascii value is 13 and \n
's is 10.
So an EOL (End of Line) will either be \r\n
or \n
. Php has the nl2br
function whose purpose is to replace all \r\n
or \n
with <br>
, the html tag for a line break.
PHP function
nl2br
converts newlines to "<br>
" breaks.
So, $wallpost=nl2br($wallpost);
should accomplish the task.