Jump to content

Using nl2br() function inside while and echo


Fishcakes

Recommended Posts

Hi

I am trying to use the nl2br function like this

while ($row = mysqli_fetch_array($query)) {
//May need this later to output pictures   
//     $imageURL = 'upload/'.rawurlencode($row["filename"]);
  echo
  
   "  <div class='divTableRow'>
<div class='divTableCell'>{$row['User']} ;</div>
<div class='divTableCell'>nl2br({$row['CommentText']});</div>
</div>


    \n";
}

However the output just looks like the attached picture.

When I check in the sql db I can see the line breaks when doing a select * from Table ;

 

image.png.6dc8f81905f12de97a48e47c6babb2bc.png

Link to comment
Share on other sites

Yes I tried this using single quotes which just outputs it as a string

<div class='divTableCell'> ' . nl2br({$row['CommentText']}) . ';</div>

And if I use double quotes as you've done it causes my page not to load

 

while ($row = mysqli_fetch_array($query)) {
//May need this later to output pictures   
//     $imageURL = 'upload/'.rawurlencode($row["filename"]);
  echo
  
   "  <div class='divTableRow'>
<div class='divTableCell'>{$row['User']} ;</div>
<div class='divTableCell'> " .  nl2br({$row['CommentText']}) . ";</div>
</div>


    \n";
}

 

Link to comment
Share on other sites

I also tried declaring the variable ($testvar)  outside the echo statement but the page still won't load even then

 

while ($row = mysqli_fetch_array($query)) {
//May need this later to output pictures   
//     $imageURL = 'upload/'.rawurlencode($row["filename"]);
$testvar = nl2br({$row['CommentText']}) ; 
  echo

  
   "  <div class='divTableRow'>
<div class='divTableCell'>{$row['User']} ;</div>
<div class='divTableCell'>  $testvar ;</div>
</div>


    \n";
}

echo $_SESSION['id'] ; 
?> 

 

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.