Jump to content

Line Breaks


shadowayex

Recommended Posts

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

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

<?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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...