Fishcakes 0 Posted April 4 Share Posted April 4 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 ; Quote Link to post Share on other sites
Barand 1,650 Posted April 4 Share Posted April 4 You cannot place a function call in a string and expect it to be executed - it just becomes part of the string. Instead you need to concatenate. For example echo "<div class='divTableCell'>" . nl2br($row['CommentText']) . "</div>"; Quote Link to post Share on other sites
Fishcakes 0 Posted April 4 Author Share Posted April 4 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"; } Quote Link to post Share on other sites
Fishcakes 0 Posted April 4 Author Share Posted April 4 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'] ; ?> Quote Link to post Share on other sites
dodgeitorelse3 5 Posted April 4 Share Posted April 4 check your semi colons ( ; ) Quote Link to post Share on other sites
Barand 1,650 Posted April 4 Share Posted April 4 $testvar = nl2br({$row['CommentText']}) ; ^ ^ and remove the curly braces. Turn on php error reporting, that line above should give Quote Parse error: syntax error, unexpected '{' in C:\inetpub\wwwroot\test\noname28.php on line ... Quote Link to post Share on other sites
Fishcakes 0 Posted April 4 Author Share Posted April 4 Ace that did it thanks Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.