Jump to content

nl2br?


RaythMistwalker

Recommended Posts

Ok there's a couple things here...

 

1)  /n is not a special character.  If you have something that's giving you /n instead of an actual newline (\n), you need to fix that.

 

2)  If you already have a lot of /n characters in your database, write a script to str_replace /n for \n

 

3)  Once you fix 1 and perform 2, nl2br will begin working.

 

-Dan

Link to comment
Share on other sites

Ok there's a couple things here...

 

1)  /n is not a special character.  If you have something that's giving you /n instead of an actual newline (\n), you need to fix that.

 

2)  If you already have a lot of /n characters in your database, write a script to str_replace /n for \n

 

3)  Once you fix 1 and perform 2, nl2br will begin working.

 

-Dan

 

Ok il answer in order..

1) That was a mistake by me. I went to the single post that had /n and changed to \n

 

2 ^

 

3) It still doesn't work :/ I can link to the thread if that would help.

Link to comment
Share on other sites

Query & Setting $PostText

      $PostQuery = "SELECT * FROM ".FORUM_POSTS." WHERE post_id='{$PostID}'";
      $PostRes = mysql_query($PostQuery, $db);
      $PostText = mysql_result($PostRes, 0, 'post_text');

 

This query works fine and gets all the data perfectly fine.

 

This part shows the text:

<td class="row2" valign="top">
            <br><?php echo nl2br($PostText); ?><br>
        </td>

 

What it returns:

Welcome to your new forum.\n\n This is a default post to show you everything is set up.

 

An example page is Here

Link to comment
Share on other sites

You are seeing the string \n.  The string \n is not a newline, it's the string \n.  That's the problem.  The Little Guy just said it up there but I wanted to make it clear:

 

$a = "\n";  //$a is now a NEWLINE

$a = '\n';  //$a is now THE STRING \n

 

You have the string \n scattered throughout your entries.  You need to do my #2 above and replace the string \n with the newline character, commonly represented in interpolated strings as \n.

 

Yes, it's confusing.  Welcome to computer science.

 

-Dan

Link to comment
Share on other sites

You are seeing the string \n.  The string \n is not a newline, it's the string \n.  That's the problem.  The Little Guy just said it up there but I wanted to make it clear:

 

$a = "\n";  //$a is now a NEWLINE

$a = '\n';  //$a is now THE STRING \n

 

You have the string \n scattered throughout your entries.  You need to do my #2 above and replace the string \n with the newline character, commonly represented in interpolated strings as \n.

 

Yes, it's confusing.  Welcome to computer science.

 

-Dan

 

That's what I thought until I just did the following:

 

$str = 'new\nline'; // should be a string literal
$query = 'INSERT INTO table (field) VALUES (\'' . $str . '\')';
$result = mysqli_query($dbc, $query);

$query = "SELECT field FROM table";
$result = mysqli_query($dbc, $query);
$array = mysqli_fetch_row($result);

echo $array[0];
echo '
<br><br>
';
echo $nl2br($array[0]);

 

The above generates this source:

[pre]

new

line

<br><br>

new<br />

line

[/pre]

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.