GB_001 Posted August 21, 2008 Share Posted August 21, 2008 Hello, I am trying to output a string from a text box that keeps it'soriginal sign that it was entered in but everytime I post it to the backend, It ignores the newlines (like when a person presses enter for a new line) and prints out only the spaces. Thankyou, -GB. <?php session_start(); include('Connect.php'); $email=$_GET['email']; $pword= md5($_GET['password']); $error="0"; mysql_query("UPDATE Ysers SET Online=1 WHERE email='$email'"); mysql_query("UPDATE Ysers SET Talking='' WHERE email='$email'"); mysql_query("UPDATE Messages SET MSG='' WHERE User1='$email'"); mysql_query("UPDATE Messages SET MSG='' WHERE User2='$email'"); $query="SELECT * FROM Ysers WHERE email='$email' AND password = '$pword' "; $result=mysql_query($query)or die(mysql_error()); if(mysql_num_rows($result)==0){ $error="<table align=left><tr><td> <font color=white>Sorry, but either the username or password you entered is not valid.<br><br><br><br><br><br><br><br><br>HELLLOOOOOOO</font></td></tr></table>"; }else{ $_SESSION['email']="$email"; $_SESSION['password']="$pword"; $_SESSION['C']=1; include "memberspage.php"; } if(!empty($error)){ echo"$error <br> $pword"; include('Register2.html'); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/120773-keeping-newlines/ Share on other sites More sharing options...
DeanWhitehouse Posted August 21, 2008 Share Posted August 21, 2008 when you echo it out, do this echo nl2br($textarea); Quote Link to comment https://forums.phpfreaks.com/topic/120773-keeping-newlines/#findComment-622503 Share on other sites More sharing options...
GB_001 Posted August 21, 2008 Author Share Posted August 21, 2008 Crap I did the wrong showcode. Here it is: <?php session_start(); include('Connect.php'); $User=$_SESSION['email']; $Friend=$_GET['F']; $Comment=$_GET['C']; $getN=mysql_query("SELECT * FROM Ysers WHERE email='$User'"); $row2 = mysql_fetch_array($getN); $Name=$row2['Name']; $PIC=$row2['Picture']; $PIC="Images/$PIC"; list($width, $height, $type, $atrib) = getimagesize($PIC); if($width>150||$height>200) { $P=$width/150; $PH=$height/150; $MW=$width/$P; $MH=$height/$PH; } $pww=(360-$MW)-15; $newstring = nl2br($Comment); $Time=date('Y-m-d'); $CF="<table height=40px width=360px style='color:white; background: black; border: 1px solid white;'> <tr> <td COLSPAN=2 style='border-bottom: 1px solid white;'>$Name -$Time</td> </tr> <tr> <td><img src=$PIC height=$MH width=$MW/></td><td valign=top style='padding: 15px;'>$newstring</td> </tr> </table><br/><b id='ZZZZZZZZZZ'>"; $Cmenty=mysql_query("SELECT * FROM Ysers WHERE email='$Friend'"); $row = mysql_fetch_array($Cmenty); $CD=$row['Comments']; mysql_query("UPDATE Ysers SET Comments='$CF $CD' WHERE email='$Friend'"); echo"$CF"; ?> Sorry about that. Quote Link to comment https://forums.phpfreaks.com/topic/120773-keeping-newlines/#findComment-622545 Share on other sites More sharing options...
DeanWhitehouse Posted August 21, 2008 Share Posted August 21, 2008 is there a question? Quote Link to comment https://forums.phpfreaks.com/topic/120773-keeping-newlines/#findComment-622553 Share on other sites More sharing options...
GB_001 Posted August 21, 2008 Author Share Posted August 21, 2008 Yes, the nl2br(); Did not seem to work. Quote Link to comment https://forums.phpfreaks.com/topic/120773-keeping-newlines/#findComment-622559 Share on other sites More sharing options...
DeanWhitehouse Posted August 21, 2008 Share Posted August 21, 2008 The function works fine. Try echo nl2br($CF); Quote Link to comment https://forums.phpfreaks.com/topic/120773-keeping-newlines/#findComment-622564 Share on other sites More sharing options...
GB_001 Posted August 21, 2008 Author Share Posted August 21, 2008 I don't know why but it still id not work. =/. Quote Link to comment https://forums.phpfreaks.com/topic/120773-keeping-newlines/#findComment-622574 Share on other sites More sharing options...
DeanWhitehouse Posted August 21, 2008 Share Posted August 21, 2008 are you sure it has any new lines in the bit you are displaying? Quote Link to comment https://forums.phpfreaks.com/topic/120773-keeping-newlines/#findComment-622582 Share on other sites More sharing options...
GB_001 Posted August 22, 2008 Author Share Posted August 22, 2008 Yes, here's a screenshot: The bottom shows what is being outputted. Quote Link to comment https://forums.phpfreaks.com/topic/120773-keeping-newlines/#findComment-622601 Share on other sites More sharing options...
GB_001 Posted August 22, 2008 Author Share Posted August 22, 2008 I'm not sure why string replacel didn't work. Quote Link to comment https://forums.phpfreaks.com/topic/120773-keeping-newlines/#findComment-622697 Share on other sites More sharing options...
Poddy Posted August 22, 2008 Share Posted August 22, 2008 I had the same problem a while ago try using <pre> tag around the output it fixed it for me Quote Link to comment https://forums.phpfreaks.com/topic/120773-keeping-newlines/#findComment-622920 Share on other sites More sharing options...
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.