monkeymade Posted December 4, 2006 Share Posted December 4, 2006 I have an sql field that is tinytext, the information in it looks like thisline 1line 2line 3But, when I pull it out and echo it, I getline 1 line 2 line 3How do I get it to keep the formattingthe information in this field is put in by users, so I have disallowed HTML code otherwise I would just tell people to type in >br> but, with users doing this themselves, its not a good idea Link to comment https://forums.phpfreaks.com/topic/29361-help-getting-something-from-mysql/ Share on other sites More sharing options...
fert Posted December 4, 2006 Share Posted December 4, 2006 [code]$text=str_replace(" ","<br>",$text);[/code] Link to comment https://forums.phpfreaks.com/topic/29361-help-getting-something-from-mysql/#findComment-134656 Share on other sites More sharing options...
keeB Posted December 4, 2006 Share Posted December 4, 2006 or, for short..$text = nl2br($text); Link to comment https://forums.phpfreaks.com/topic/29361-help-getting-something-from-mysql/#findComment-134682 Share on other sites More sharing options...
tracy Posted December 4, 2006 Share Posted December 4, 2006 You want it displayed in a certain format, so having a table in your display page and using php to call the data from the server in each cell would accomplish that...a php get function where the cell data in the table is... You would assign a value to each piece of data, write the simple table into the page and use php to call the data into each cell... Link to comment https://forums.phpfreaks.com/topic/29361-help-getting-something-from-mysql/#findComment-134782 Share on other sites More sharing options...
obsidian Posted December 4, 2006 Share Posted December 4, 2006 [quote author=tracy link=topic=117257.msg478375#msg478375 date=1165239234]You want it displayed in a certain format, so having a table in your display page and using php to call the data from the server in each cell would accomplish that...a php get function where the cell data in the table is... You would assign a value to each piece of data, write the simple table into the page and use php to call the data into each cell...[/quote]I'd definitely recommend you go with the simpler solution that KeeB suggested above. I'll try to explain [b]why[/b] you need to use that function: when you enter text into a textarea (or copy it from a text editor), your newline characters or carriage returns are saved as the character "\n" or "\r" depending on your system. So, in order to get those newlines to be remembered in HTML, you have to translate them to HTML line breaks. That's where the function comes in: nl2br() changes all newline characters to "<br />" tags for display purposes. Link to comment https://forums.phpfreaks.com/topic/29361-help-getting-something-from-mysql/#findComment-134787 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.