I have two files. First file is a form and the second file displays result.
First file:
Basically, textarea
's linebreaks are \r\n
in Internet Explorer, and \n
in all other browsers (including Mac's). IE uses \n
too since version 9.
There are numerous ways to fix your code. For example, you could try preg_split() :
preg_split('/(?:\r\n|\n)/', $text);
However, I haven't tested the performances of this proposal.
Also, very important, be sure to put the \r\n
before the \n
in the regex!
Besides, trim() is way more suited than str_replace() (of course if you still need it).
Try nl2br() function, could be carriage return or new line (\r\n, \n\r, \n and \r).
Use trim()
instead of str_replace
I know its late but may help others.
use this in when document indentation is required.
$('document').ready(function()
{
$('textarea').each(function(){
$(this).val($(this).val().trim());
}
);
});
Maybe it's non space whitespaces like non-break-spaces (nbsp) or some part of a linebreak combination?
You can use trim function instead of using str_replace
to do that.