Jump to content

[SOLVED] Storing text as it's typed


magnetica

Recommended Posts

Hi I have a comments box (textarea) on my site and want to know how to store the text written exactly as it's typed!

 

For example everything i'm writing here will appear as i've typed, all the line breaks will be in place etc... With my script it only stores the text and not any line breaks etc..

 

How do I do this? Do I need to create a parser to recognise line breaks?

Link to comment
https://forums.phpfreaks.com/topic/71277-solved-storing-text-as-its-typed/
Share on other sites

Your script probably is storing line breaks, but a web browser doesn't display line breaks.

 

Try

 

<?php
$search = array("\r\n", "\n", "\r");
$replace = "\n<br />"

str_replace($search, $replace, $_POST['textarea']);

?>

 

If you want it to also break in the same soft breaks where the text wrapped to a new line in the text area, add wrap="hard" in the textarea tag.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.