JJohnsenDK Posted March 9, 2007 Share Posted March 9, 2007 Hey I have a input form where i type in alot of text, this text is then stored in the database. When i pull the data out of the database to show on the screen there are no line breaks. The text is just printed out in one long text. How do i make automaticly line breaks without using <br />, when i type in the form input? I tried this: <?php function get_gameday($news_subject){ $qry = mysql_query("SELECT news_news FROM fusion_news WHERE `news_subject` = '$news_subject'") or die(mysql_error()); $row = mysql_fetch_array($qry); $news_news = stripslashes($row['news_news']); $news_news = nl2br($news_news); return $news_news; } echo get_gameday("GameDay optakt: ACH - SIF"); ?> This script just returns the text in one long text without line breaks. Hope someone can help. Link to comment https://forums.phpfreaks.com/topic/41927-how-do-i-make-line-breaks-without/ Share on other sites More sharing options...
Orio Posted March 9, 2007 Share Posted March 9, 2007 Look into wordwrap(). I think using something like this would be good for you: wordwrap($text, 60, "<br />"); Orio. Link to comment https://forums.phpfreaks.com/topic/41927-how-do-i-make-line-breaks-without/#findComment-203313 Share on other sites More sharing options...
skali Posted March 9, 2007 Share Posted March 9, 2007 Are you removing line breaks when you are inserting data into the database?? And are you typing in data and changing line by pressing enter? nl2br() converts line breaks into <br> tags only, so if it is a very long line but no line breaks (enter button was never pressed) then nl2br() will not insert <BR> Link to comment https://forums.phpfreaks.com/topic/41927-how-do-i-make-line-breaks-without/#findComment-203315 Share on other sites More sharing options...
mbtaylor Posted March 9, 2007 Share Posted March 9, 2007 You could write a function which uses explode to split the string on a space which would create an array of words. Then loop through the array and insert a <br /> every Nth word. e.g $words = explode (" ", $string); $numtoseparate = 10; #number of words before inserting a <br /> foreach ($words as $word) { $i++; print ($word); if ($i == $numtoseparate) { print ("<br />"); } } Link to comment https://forums.phpfreaks.com/topic/41927-how-do-i-make-line-breaks-without/#findComment-203323 Share on other sites More sharing options...
Orio Posted March 9, 2007 Share Posted March 9, 2007 You could write a function which uses explode to split the string on a space which would create an array of words. Then loop through the array and insert a <br /> every Nth word. e.g $words = explode (" ", $string); $numtoseparate = 10; #number of words before inserting a <br /> foreach ($words as $word) { $i++; print ($word); if ($i == $numtoseparate) { print ("<br />"); } } Or you could simply use wordwrap() that does that for you, just with more options (as I mentioned in my first post). Orio. Link to comment https://forums.phpfreaks.com/topic/41927-how-do-i-make-line-breaks-without/#findComment-203332 Share on other sites More sharing options...
mbtaylor Posted March 9, 2007 Share Posted March 9, 2007 Does it? * Reads manual page. Sorry to dupe your post then. Link to comment https://forums.phpfreaks.com/topic/41927-how-do-i-make-line-breaks-without/#findComment-203333 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.