anujphp Posted November 18, 2008 Share Posted November 18, 2008 hello I have stored a paragraph in mysql database and when i try to retrive it and sisplay i want to format the paragrapg... The paragraph is like this 1.some text 2.again some text 3.again some text 4.again some text I want my output to be like this 1.some text 2.again some text 3.again some text 4.again some text and so on i am able to retrive the praragrapg in a variable like the variable is $paragraph now i dont no how to cut the line after a number and point(fullstop) Please Help me guys...its urgent THANKING YOU IN ADVANCE Quote Link to comment https://forums.phpfreaks.com/topic/133243-solved-formatting-a-value-retirved-from-database/ Share on other sites More sharing options...
.josh Posted November 18, 2008 Share Posted November 18, 2008 How/why is it being stored with numbers like that in the first place? Can't you add line breaks to it when you initially store it? Quote Link to comment https://forums.phpfreaks.com/topic/133243-solved-formatting-a-value-retirved-from-database/#findComment-692956 Share on other sites More sharing options...
bogeyman Posted November 19, 2008 Share Posted November 19, 2008 Yeah, I think you should store it with the line breaks and use nl2br() function to convert the line breaks into <br> tag. Quote Link to comment https://forums.phpfreaks.com/topic/133243-solved-formatting-a-value-retirved-from-database/#findComment-693173 Share on other sites More sharing options...
anujphp Posted November 19, 2008 Author Share Posted November 19, 2008 the text are a sequence of step to be followed so the number comes in to effect, the test input field is a text area,I dont no how to add line break(</br>) while the user write in the text area,I cant ask user to use an html code while writting in a text area,as user are not tech savy.can you please help me out Can you please give me an example of nl2br(). function Quote Link to comment https://forums.phpfreaks.com/topic/133243-solved-formatting-a-value-retirved-from-database/#findComment-693182 Share on other sites More sharing options...
gmcalp Posted November 19, 2008 Share Posted November 19, 2008 nl2br means: new line (carriage return) to <br/> here's an example of how I have used it: // convert newline characters to HTML break tag ( <br /> ) $desc = nl2br($desc); Quote Link to comment https://forums.phpfreaks.com/topic/133243-solved-formatting-a-value-retirved-from-database/#findComment-693188 Share on other sites More sharing options...
anujphp Posted November 19, 2008 Author Share Posted November 19, 2008 THANKS A LOT particulary gmcalp and bogeyman I am able to solve the issue.thanks once again. As suggested by you i have used the function nl2br and able to get the result as i wanted. Quote Link to comment https://forums.phpfreaks.com/topic/133243-solved-formatting-a-value-retirved-from-database/#findComment-693204 Share on other sites More sharing options...
redarrow Posted November 19, 2008 Share Posted November 19, 2008 <?php echo nl2br("Hello there!\n Iam redarrow,this is xhtml way!"); echo"<br><br>"; //might give a error..... echo nl2br("Hi there iam\r\nredarrow\r\nThis is the html way", false); ?> Quote Link to comment https://forums.phpfreaks.com/topic/133243-solved-formatting-a-value-retirved-from-database/#findComment-693215 Share on other sites More sharing options...
bogeyman Posted November 20, 2008 Share Posted November 20, 2008 THANKS A LOT particulary gmcalp and bogeyman I am able to solve the issue.thanks once again. As suggested by you i have used the function nl2br and able to get the result as i wanted. You're welcome. Quote Link to comment https://forums.phpfreaks.com/topic/133243-solved-formatting-a-value-retirved-from-database/#findComment-694088 Share on other sites More sharing options...
anujphp Posted November 21, 2008 Author Share Posted November 21, 2008 you dont need to use any html tag.... suppose you have saved the value of textarea in a database with column name as paragraph..while writting the paragraph in textarea you have pressed the enter key then whiel displaying the paragraph from database you just need to use the nl2br function like this echo nl2br($row['paragraph']); //i am assuming that you need to display the paragraphy as it is written in text area..each line in a new line Quote Link to comment https://forums.phpfreaks.com/topic/133243-solved-formatting-a-value-retirved-from-database/#findComment-695131 Share on other sites More sharing options...
redarrow Posted November 21, 2008 Share Posted November 21, 2008 ur correct u dont need to use any html tags....... when u enter info to the database from a form Each time the user press enter the database updates with specill char, and then use nl2br() to see the date and the line brakes will be shown....... Quote Link to comment https://forums.phpfreaks.com/topic/133243-solved-formatting-a-value-retirved-from-database/#findComment-695648 Share on other sites More sharing options...
redarrow Posted November 21, 2008 Share Posted November 21, 2008 read this mate, a forum member just told me somethink very intresting, related to this post........ http://www.phpfreaks.com/forums/index.php/topic,226580.0.html Quote Link to comment https://forums.phpfreaks.com/topic/133243-solved-formatting-a-value-retirved-from-database/#findComment-695673 Share on other sites More sharing options...
plodos Posted November 22, 2008 Share Posted November 22, 2008 <?php if ($_POST['action'] == 'Go Go Go') { $text = nl2br($_POST['foo']); // now do whatever you want with text, insert it into a database or display it to the user } ?> <html> <form method="post" action=""> <textarea name="foo"></textarea> <input type="submit" name="action" value="Go Go Go" /> </form> </html> related link : http://www.phpfreaks.com/forums/index.php/topic,225590.msg1039786.html#msg1039786 Quote Link to comment https://forums.phpfreaks.com/topic/133243-solved-formatting-a-value-retirved-from-database/#findComment-696069 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.