i have one text area
<textarea name="message" id="message" class="text_field" style="height:200px; width:500px"></textarea>
if i type data in the text area like this
hello
this is my test message
bye
'abc'
i use following statement to get data from text area
var message = $('#message').attr('value');
i pass this value to other php file like
var data = {message:message};
$.ajax({
type: "POST",
url: "show.php",
data: data,
etc
when i see data in post value firebug in show exactly i type the data (with new lines & spaces etc)
and in php file
$message=$_POST['message'];
$Content = file_get_contents($temp_page);
$Content = str_replace('%%a%%', $message, $Content);
now when i use
echo $Content
i get all the text in one line not exact i type in text area…
hello this is my test message bye 'abc'
Thanks
That is because browsers don’t print newlines outside textareas or other elements that are defined to print the output as is, for example
<pre>.You need to use
echo nl2br($Content);to substitute newlines with<br />elements, which is the equivalent of a newline in (x)HTML.