Jump to content

Recommended Posts

I have my data being stored into my database as a normal person would with my messages being put into a text filed that keeps all of the new lines etc.

 

However, when i call the code and place it into a page it puts in an extra 4 br tags before every line.

 

Here is my code for the page:

 

<?php

// start session
session_start();
require_once('page_header.php');
// set sessions to variables
$id = $_SESSION['id'];
$username = $_SESSION['username'];

// set board id
$board = '1';
// get max post_num
$query = mysql_query("SELECT MAX(post_num) AS `post_num_max` FROM `zBoard_messages` WHERE board_id='$board'") or die(mysql_error());
$fetch= mysql_fetch_assoc($query) or die(mysql_error());
$post_num_max = $fetch['post_num_max'];

for ($pn = 1; $pn <= $post_num_max; $pn++) 
{

// select message id's from db
$query = mysql_query("SELECT `id`,`poster_id`, `subject`, `message`, `date` FROM `zBoard_messages` WHERE board_id='$board' && post_num='$pn'") or die(mysql_error());
$row = mysql_fetch_assoc($query) or die(mysql_error());

// set db results to variables
$id = $row['id'];
$poster_id = $row['poster_id'];
$subject = $row['subject'];
$text = $row['message'];
$date = $row['date'];

// get username
$query = mysql_query("SELECT username FROM `zBoard_users` WHERE id='$poster_id'") or die(mysql_error());
$row = mysql_fetch_assoc($query) or die(mysql_error());
$poster = $row['username'];
// convert message into viewer message
require('bbcode.php');
// get legible date
list ($date,$time) = explode(' ',$date);
list ($year,$month,$day) = explode('-',$date);
$date = "$day/$month/$year";

//display contents
?>
<br />
<center>
<table width="80%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="20%" align="center"><?php echo "#".$pn.""; ?><br /><hr></td>
<td width="80%" align="center"><b>Subject:</b> <?php echo $subject; ?> | <b>Posted at:</b> <?php echo $time; ?> on <?php echo $date; ?><br /><hr></td>
</tr>
<tr>
<td width="20%" align="center" valign="top">
	<table width="100%" cellspacing="0" cellpadding="0" border="0">
	<tr>
	<td width="100%" align="center">
	<?php echo ucfirst($poster); ?>
	</td>
	</tr>
	<tr>
	<td width="100%" align="center">
	<?php echo"<img src=\"".$poster_id.".gif\" width=\"45\" height=\"57\" border=\"0\" alt=\"".ucfirst($poster)."'s Avatar\" />"; ?>
	</td>
	</tr>
	</table>
</td>
<td width="70%" align="left">
	<table width="100%" cellspacing="0" cellpadding="0" border="0">
	<tr>
	<td width="100%" align="left">
	<?php echo $text; ?>
	</td>
	</tr>
	</table>
</td>
</tr>
<tr>
<td colspan="2">
<hr>
</td>
</tr>
</table>
</center>
<?php
}
?>

 

Example

 

stored in database as:

 

hello this

is a random

message.

 

However, with the above code it is printing out this

 

<br /><br /><br /><br />hello this<br /><br /><br /><br /><br />is a random<br /><br /><br /><br /><br />message

 

Thanks (sorry the message isnt very clear),

 

~ Chocopi

Link to comment
https://forums.phpfreaks.com/topic/55297-new-lines-being-inputted/
Share on other sites

in my code i use: mysql_real_escape_string() and nl2br() and the lines appear, so i have resorted to having to use:

 

<?php
$text = str_replace('<br /><br /><br />','',$text);
$text = str_replace('\r\n','<br />',$text);
?>

 

the \r\n has only appeared since i used mysql_real_escape_string() so is there a way to escape them

 

Cheers,

 

~ Chocopi

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.