tommybfisher Posted September 5, 2011 Share Posted September 5, 2011 I have created a php guestbook for my site. The only problem I have with it is that when a user puts a carriage return in their entry, it is not replicated in the viewed post. I'm trying to figure out how I turn these returns into <br /> tags for display. Do I do something with the php that handles the input (i.e. somehow replace carriage returns with <br />'s) or is it to do with the output php code? Any pointers would be gratefully appreciated. This is the php for the guestbook entries output: <?php include "connection.php"; $table = "guestbook"; $data = mysql_query("SELECT * FROM $table ORDER BY id DESC") or die(mysql_error()); echo "<div class='divide_message'>"; while($info = mysql_fetch_array( $data )) { $date = date("d/m/y",strtotime($info['date'])); echo "<div class='block message'>"; echo "<div class='message_name'>" . $info['name'] . ""; echo "<span class='date'>" . $date . "</span></div><br />"; echo "<div class='message_message'>" . $info['message'] . "</div>"; echo "</div>"; } echo "</div>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/246464-converting-guestbook-entry-newlines-to-html-tags/ Share on other sites More sharing options...
JKG Posted September 5, 2011 Share Posted September 5, 2011 you could try nl2br() or a visual editor. ckeditor is the best in my opinion. Quote Link to comment https://forums.phpfreaks.com/topic/246464-converting-guestbook-entry-newlines-to-html-tags/#findComment-1265594 Share on other sites More sharing options...
tommybfisher Posted September 5, 2011 Author Share Posted September 5, 2011 np2br was exactly what I was looking for. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/246464-converting-guestbook-entry-newlines-to-html-tags/#findComment-1265619 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.