chocopi Posted June 12, 2007 Share Posted June 12, 2007 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 More sharing options...
chocopi Posted June 12, 2007 Author Share Posted June 12, 2007 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 Link to comment https://forums.phpfreaks.com/topic/55297-new-lines-being-inputted/#findComment-273466 Share on other sites More sharing options...
kenrbnsn Posted June 12, 2007 Share Posted June 12, 2007 Or you could try: <?php $text = nl2br(str_replace('\r\n',"\r\n",$text)); ?> I have heard the mysql_real_escape_string() seems to do that to newline characters. Ken Link to comment https://forums.phpfreaks.com/topic/55297-new-lines-being-inputted/#findComment-273468 Share on other sites More sharing options...
chocopi Posted June 14, 2007 Author Share Posted June 14, 2007 kool thanks ken, but when i do that it causes new lines on html tags Link to comment https://forums.phpfreaks.com/topic/55297-new-lines-being-inputted/#findComment-274645 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.