magnetica Posted September 30, 2007 Share Posted September 30, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/71277-solved-storing-text-as-its-typed/ Share on other sites More sharing options...
Barand Posted September 30, 2007 Share Posted September 30, 2007 If we can see how you are doing it, we may be able to see what's wrong. Quote Link to comment https://forums.phpfreaks.com/topic/71277-solved-storing-text-as-its-typed/#findComment-358561 Share on other sites More sharing options...
xylex Posted September 30, 2007 Share Posted September 30, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/71277-solved-storing-text-as-its-typed/#findComment-358562 Share on other sites More sharing options...
magnetica Posted September 30, 2007 Author Share Posted September 30, 2007 Thanks for the quick reply. The str_replace function works well! Thanks Quote Link to comment https://forums.phpfreaks.com/topic/71277-solved-storing-text-as-its-typed/#findComment-358567 Share on other sites More sharing options...
Barand Posted September 30, 2007 Share Posted September 30, 2007 With my script it only stores the text and not any line breaks etc.. You mean you didn't check what was being stored in your db before posting that only text was being stored? Quote Link to comment https://forums.phpfreaks.com/topic/71277-solved-storing-text-as-its-typed/#findComment-358576 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.