cozzy1984 Posted February 15, 2008 Share Posted February 15, 2008 Hi, just a quick question. I've got a description field on a form and have it to inserted into a text mysql field. Problem is when i am displaying the data in a table with an echo statement. It doesn't output i the same way it was typed in. For instance it doesn't take new lines when i had done so we typing into the textarea. Is there a better way of doing this, possibly storing it as some other type in the database. Also there is a problem in that if the user typed in a long continuous word without spaces, it makes the table i am displaying them in really wide and ruins the design. Is there a way round this also? Would appreciate any ideas. Link to comment https://forums.phpfreaks.com/topic/91272-php-and-the-textarea-field/ Share on other sites More sharing options...
mpharo Posted February 15, 2008 Share Posted February 15, 2008 lets see your code for the textarea and an example of the output code.... Link to comment https://forums.phpfreaks.com/topic/91272-php-and-the-textarea-field/#findComment-467770 Share on other sites More sharing options...
schilly Posted February 15, 2008 Share Posted February 15, 2008 My CSS isn't great but you should be able to make the table wrap any extra long words. Also newlines \n won't work in the rendered html page but will work in the source code. (Not positive) Link to comment https://forums.phpfreaks.com/topic/91272-php-and-the-textarea-field/#findComment-467799 Share on other sites More sharing options...
drewbee Posted February 15, 2008 Share Posted February 15, 2008 The textarea passes a new line break on entering; When you are displaying the data entered from the textarea, try wrapping the function nl2br() around the textarea data. This will convert every new line to a <br> Link to comment https://forums.phpfreaks.com/topic/91272-php-and-the-textarea-field/#findComment-467818 Share on other sites More sharing options...
marcus Posted February 15, 2008 Share Posted February 15, 2008 *to an HTML break Link to comment https://forums.phpfreaks.com/topic/91272-php-and-the-textarea-field/#findComment-467820 Share on other sites More sharing options...
drewbee Posted February 15, 2008 Share Posted February 15, 2008 lol, whoops. Doesn't this forum properly convert html? haha Link to comment https://forums.phpfreaks.com/topic/91272-php-and-the-textarea-field/#findComment-467939 Share on other sites More sharing options...
richardw Posted February 15, 2008 Share Posted February 15, 2008 try investing preg_replace to search the field and break and hyphenate long or mistyped words <?php $result = "OneTooManyHighlights and the start of a sentance break to prevent css distortion breakingstylestyle"; $result = preg_replace("/([^\s]{14})/","$1 ",$result); echo $result; ?> There is a forum here on Regular Expressions that might be worth exploring. The limitation on this routine is that it doesn't trap for emails or links. If that is part of your text, you will have to expand the regex. Also, don't forget the earlier nl2br() for those extra lines Link to comment https://forums.phpfreaks.com/topic/91272-php-and-the-textarea-field/#findComment-468007 Share on other sites More sharing options...
schilly Posted February 15, 2008 Share Posted February 15, 2008 ah right. nl2br. forgot about that one. Link to comment https://forums.phpfreaks.com/topic/91272-php-and-the-textarea-field/#findComment-468035 Share on other sites More sharing options...
cozzy1984 Posted February 16, 2008 Author Share Posted February 16, 2008 Cheers lads, i now have when adding the advert: $description = nl2br($_POST['description']); and when displaying it my code is: echo "<td colspan='2' height='60' valign='top'>".substr($description,0,150). "...</td>"; Which limits the character count to 150 i think and then puts ... at end. I would prefer this to stop at word count rather than character count as it can stop in middle of a word, if anyone new code for this i would appreciate it. However it still can be ruined by someone typing a contiuous long word, as it'll make the table long and upset the whole design. Link to comment https://forums.phpfreaks.com/topic/91272-php-and-the-textarea-field/#findComment-468345 Share on other sites More sharing options...
schilly Posted February 18, 2008 Share Posted February 18, 2008 However it still can be ruined by someone typing a contiuous long word, as it'll make the table long and upset the whole design. You can use CSS and add: word-wrap: break-word; to your class and it will break up any big words. Link to comment https://forums.phpfreaks.com/topic/91272-php-and-the-textarea-field/#findComment-469627 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.