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
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>

Link to comment
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.