johnsmith153 Posted September 10, 2008 Share Posted September 10, 2008 I am doing a message board. I am using html entities to stop people using tags etc. However if I typed exactly what I have typed here in my message board, I would get: " I am doing a message board. I am using html entities to stop people using tags etc. However if I typed exactly what I have typed here in my message board, I would get: " I still want people to be able to press enter etc. - what do I do? Quote Link to comment https://forums.phpfreaks.com/topic/123646-how-to-allow-line-breaks-but-keep-html-entities/ Share on other sites More sharing options...
DamienRoche Posted September 10, 2008 Share Posted September 10, 2008 Not sure what you mean with the " You can try encapsulate your posts with <pre> </pre> which preserves line breaks. Quote Link to comment https://forums.phpfreaks.com/topic/123646-how-to-allow-line-breaks-but-keep-html-entities/#findComment-638505 Share on other sites More sharing options...
The Little Guy Posted September 10, 2008 Share Posted September 10, 2008 Save the info into your database. When you read it back do this: // Make you sql query $row = mysql_fetch_array($sql); echo nl2br($row['message']); Quote Link to comment https://forums.phpfreaks.com/topic/123646-how-to-allow-line-breaks-but-keep-html-entities/#findComment-638510 Share on other sites More sharing options...
xoligy Posted September 10, 2008 Share Posted September 10, 2008 I have line breaks added via bbcode so if the bbcode file is missing the line you wrote wouldnt have line breaks it be all joined together. If your thinking of using bbcode for smiles then maybe you could try that this allows line breaks as i use it on a news script. Quote Link to comment https://forums.phpfreaks.com/topic/123646-how-to-allow-line-breaks-but-keep-html-entities/#findComment-638515 Share on other sites More sharing options...
johnsmith153 Posted September 10, 2008 Author Share Posted September 10, 2008 great, thanks. The Little Guy's solution is perfect. Just another thought. What if people tried to press enter many times. Would I be able to stop this? Ie PHP to pick up more than 4 line breaks and convert it all into 2 etc. Test: see how PHP Freaks deals with this: Hello Hello Quote Link to comment https://forums.phpfreaks.com/topic/123646-how-to-allow-line-breaks-but-keep-html-entities/#findComment-638525 Share on other sites More sharing options...
wildteen88 Posted September 10, 2008 Share Posted September 10, 2008 Test: see how PHP Freaks deals with this: Hello Hello You'll have to use regex to convert multiple new lines in to a single newline, eg $str = "Hello Hello World"; $str = preg_replace('|(\s){3,}|s', "\n", $str); echo nl2br($str); Quote Link to comment https://forums.phpfreaks.com/topic/123646-how-to-allow-line-breaks-but-keep-html-entities/#findComment-638531 Share on other sites More sharing options...
johnsmith153 Posted September 10, 2008 Author Share Posted September 10, 2008 Sorry, one more. Wildteen88 has a good solution, but this would convert: Hello How are you? From Jim into: Hello How are you? From Jim Ideally it would do: Hello How are you? From Jim In other words, it allows 2 line breaks, but converts 20 (for example) into 2 (not 1) Quote Link to comment https://forums.phpfreaks.com/topic/123646-how-to-allow-line-breaks-but-keep-html-entities/#findComment-638565 Share on other sites More sharing options...
xoligy Posted September 10, 2008 Share Posted September 10, 2008 thats a good question and a nice answer! Cause a double line break is always helpful i may have to borrow the code too lol Quote Link to comment https://forums.phpfreaks.com/topic/123646-how-to-allow-line-breaks-but-keep-html-entities/#findComment-638568 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.