One line break should be a <br />
and two should signify a paragraph break. So just look for your two "\n\n"
statements in your code and replace all those with </p><p>
and then just wrap <p></p>
tags around the entire string.
Here's the series of steps that should take place:
- Submit to your PHP server and set
$input = $_POST['input'];
- Do
$input = trim($input)
to remove all the extra linebreaks and whitespace from the start and end of the input.
- Then do
$input = str_replace($input, "\n\n",'</p><p>');
- Then do
$input = '<p>' . $input . '</p>';
---- EDIT ----
One final thing to keep in mind. If you do not want to have a bunch of empty <p></p>
tags when If a user enters more than two consecutive linebreaks then you need to look out for that.
To get around that, do this instead.
$input = preg_replace("/\n(?:\n)+/",'</p><p>', $input)
//you may need to set the PHP PCRE multiline flag for this to work