Jump to content

How do i make line breaks without <br />??


JJohnsenDK

Recommended Posts

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

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>

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 />");
} 
}

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.