shadowayex Posted June 19, 2008 Share Posted June 19, 2008 I don't know why, but I recently updated my code to a cleaner code, and something went wrong.On my site, there's a messaging system. When a user replies to a message, it adds a divider that identifies who sent the original message. The whole reply script looks like this: elseif($mode == "reply") { $message = mysql_query("SELECT * FROM messages WHERE MsgId = '$id'"); $row = mysql_fetch_array($message); if($user == $row['Receiver']) { $result = '<form action="messages.php?mode=sendmsg" method="post">'; $result .= '<div>'; $result .= '<p>To: <input type="text" name="to" value="' . $row['Sender'] . '" /></p>'; $result .= '<p>Subject: <input type="text" name="subject" value="' . stripslashes($row['Subject']) . '" /></p>'; $result .= '<p>Message: <br />'; $result .= '<textarea rows="10" cols="50" name="message">'; $result .= '\n\n\n---------------\n'; $result .= $row['Sender'] . '\n'; $result .= '---------------\n\n'; $result .= stripslashes($row['Message']); $result .= '</textarea></p>'; $result .= '<input type="submit" name="submit" value="Send" />'; $result .= '</div>'; $result .= '</form>'; } else { $result = 'Message does not exist!'; } mysql_free_result($message);} Before, I had the code in the body of the page echoing the whole thing, but then I changed it so the code is as the top of the page, and the only thing in the body section is a call to the $result variable. Before I changed the code, the \n would put line breaks in the textarea. Now it just writes it out, so the textarea looks like: \n\n\n---------------\n(username)\n---------------\n\n(message) Instead of: ---------------(username)---------------(message) Why did it stop working and how do I fix it? Link to comment Share on other sites More sharing options...
jeffman Posted June 19, 2008 Share Posted June 19, 2008 Use double-quote marks to interpolate escaped chars, variables, etc. Link to comment Share on other sites More sharing options...
shadowayex Posted June 19, 2008 Author Share Posted June 19, 2008 Oh... Is there a way to make it line break without double quotes. It's not that big of a deal if I have to change those to double quotes, but I'd like to keep everything consistent. Link to comment Share on other sites More sharing options...
Wander Posted June 19, 2008 Share Posted June 19, 2008 nop, \n only works between dubblequotes, only way to do without dubblequotes is$a = 'newline';or$n = "\n";$a = 'new' .$n.'line'; Link to comment Share on other sites More sharing options...
king Posted June 20, 2008 Share Posted June 20, 2008 <?php$result .= "\n\n\n".'---------------'."\n";?> That's how I would do it. There are times when you need double quotes.Edit: Make your code look a bit neater $row['Subject'] = stripslashes($row['Subject']);$result = <<<END<form action="messages.php?mode=sendmsg" method="post"><div><p>To: <input type="text" name="to" value="{$row['Sender']}" /></p><p>Subject: <input type="text" name="subject" value="{$row['Subject']}" /></p><p>Message: <br /><textarea rows="10" cols="50" name="message">END; Link to comment Share on other sites More sharing options...
justsomeguy Posted June 23, 2008 Share Posted June 23, 2008 It would be quicker to just do this: <?php$result .= "\n\n\n---------------\n";?> There's no need to concatenate two string literals. Link to comment Share on other sites More sharing options...
shadowayex Posted June 23, 2008 Author Share Posted June 23, 2008 Ok well I'll just have to deal with double quotes when I want line breaks I suppose. Thanks for the responses. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.