Jump to content

[SOLVED] Problem using nl2br()


Cory94bailly

Recommended Posts

function printSticky($result1)
{
        echo "<table>\n";
        while($news = mysql_fetch_assoc($result1))
        {
            echo <<<HTML
<span class="announcement">Announcement:</span> <b>{$news['news_title']}</b><br />
<hr width="300" align="left" />
{$news['news_body']}
<br />
HTML;
        }

        echo "\n</table><br />";
    }

 

 

Where would I put nl2br()???

 

 

I tried many things and got errors everywhere.. lol ;)

Link to comment
https://forums.phpfreaks.com/topic/151514-solved-problem-using-nl2br/
Share on other sites

Put echoed string in it.

function printSticky($result1)
{
        echo nl2br("<table>\n");
        while($news = mysql_fetch_assoc($result1))
        {
            echo <<<HTML
<span class="announcement">Announcement:</span> <b>{$news['news_title']}</b><br />
<hr width="300" align="left" />
{$news['news_body']}
<br />
HTML;
        }

        echo nl2br("\n</table><br />");
    }

Put echoed string in it.

function printSticky($result1)
{
        echo nl2br("<table>\n");
        while($news = mysql_fetch_assoc($result1))
        {
            echo <<<HTML
<span class="announcement">Announcement:</span> <b>{$news['news_title']}</b><br />
<hr width="300" align="left" />
{$news['news_body']}
<br />
HTML;
        }

        echo nl2br("\n</table><br />");
    }

 

That's not what I want to be turned into <br>s..

 

I want this: {$news['news_body']}

I assume you want to add line breaks to your $news['news_body']. If so, add nl2br() before echoing it:

 

<?php
function printSticky($result1)
{
    $news['news_body'] = nl2br($news['news_body']);

        echo "<table>\n";
        while($news = mysql_fetch_assoc($result1))
        {
            echo <<<HTML
<span class="announcement">Announcement:</span> <b>{$news['news_title']}</b><br />
<hr width="300" align="left" />
{$news['news_body']}
<br />
HTML;
        }

        echo "\n</table><br />";
    }
?>

This line:

$news['news_body'] = nl2br($news['news_body']);

 

Should be within then while loop

<?php
function printSticky($result1)
{
        echo "<table>\n";
        while($news = mysql_fetch_assoc($result1))
        {
            $news['news_body'] = nl2br($news['news_body']);

            echo <<<HTML
<span class="announcement">Announcement:</span> <b>{$news['news_title']}</b><br />
<hr width="300" align="left" />
{$news['news_body']}
<br />
HTML;
        }

        echo "\n</table><br />";
    }
?>

This line:

$news['news_body'] = nl2br($news['news_body']);

 

Should be within then while loop

<?php
function printSticky($result1)
{
        echo "<table>\n";
        while($news = mysql_fetch_assoc($result1))
        {
            $news['news_body'] = nl2br($news['news_body']);

            echo <<<HTML
<span class="announcement">Announcement:</span> <b>{$news['news_title']}</b><br />
<hr width="300" align="left" />
{$news['news_body']}
<br />
HTML;
        }

        echo "\n</table><br />";
    }
?>

 

Wooh! I love you ;)

 

Thanks  :o

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.