Giddy Rob Posted February 8, 2007 Share Posted February 8, 2007 Hey, I have some text data in a database that im outputting to a page. The text is made up of two paragraphs divided by a line space i.e. "rar rar rar. rar rar rar" When I use mysql_fetch_array to get the value out of the database it gets rid of the spacing i.e. "rar rar rar. rar rar rar" I have checked in the database and it conserves the line spacing so I guess it must be something to do with the php? Is there a way i can output the value with the line spacing intact? Any help would be great. Cheers Rob ??? Link to comment https://forums.phpfreaks.com/topic/37605-solved-outputting-text/ Share on other sites More sharing options...
trq Posted February 8, 2007 Share Posted February 8, 2007 Take a look at nl2br. Link to comment https://forums.phpfreaks.com/topic/37605-solved-outputting-text/#findComment-179811 Share on other sites More sharing options...
obsidian Posted February 8, 2007 Share Posted February 8, 2007 Thorpe is definitely pointing you at the right function, but I wanted to give a little more explanation. When you depress the enter key within a text area, you are simply applying a newline character ('\n') to the text. The function thorpe has pointed you to changes those newline characters to <br /> tags, hence cleaning up your HTML output. Now, keep in mind that when exporting source code, plain text and/or text emails, you need to use '\n' or '\r\n' (Windows safe) to designate linebreaks. Link to comment https://forums.phpfreaks.com/topic/37605-solved-outputting-text/#findComment-179819 Share on other sites More sharing options...
Giddy Rob Posted February 8, 2007 Author Share Posted February 8, 2007 Thanks for the reply, but depending on the record depends where the line spacing is (if any) so it needs to be done automatically if possible? I am basically using one page that gets fed a record from a database depending on the id number so some text might be just one paragraph, but also there might be three! It all depends on what the user has put in the database. I would like it to be able to detect the spacing and put \r\n. Is this possible? Cheers Rob Link to comment https://forums.phpfreaks.com/topic/37605-solved-outputting-text/#findComment-179821 Share on other sites More sharing options...
obsidian Posted February 8, 2007 Share Posted February 8, 2007 Thanks for the reply, but depending on the record depends where the line spacing is (if any) so it needs to be done automatically if possible? I am basically using one page that gets fed a record from a database depending on the id number so some text might be just one paragraph, but also there might be three! It all depends on what the user has put in the database. I would like it to be able to detect the spacing and put \r\n. Is this possible? Cheers Rob That's what the function thorpe showed you does. It finds the line breaks that the users have inserted into their text and changes them to <br /> tags. Link to comment https://forums.phpfreaks.com/topic/37605-solved-outputting-text/#findComment-179823 Share on other sites More sharing options...
Giddy Rob Posted February 8, 2007 Author Share Posted February 8, 2007 Ah, cool. I will have a look. Thanks for your help everyone. Cheers Rob Link to comment https://forums.phpfreaks.com/topic/37605-solved-outputting-text/#findComment-179828 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.