NewbieBryan Posted July 10, 2009 Share Posted July 10, 2009 Hi All, I have created an application that collects information for various people (form submissions) and writes this back to a MySQL db (VARCHAR) All works well but when I read back the "Comments" table then the string is improperly formated, well rather it doesn't remember the formatting. So - for example: If someone typed in: Hello all, I have the following A dog, A Cat when I write it to screen it displays Hello all,I have the following A dog,A Cat Is there a manner in which I can keep the formatting (spaces, etc): Tx Link to comment https://forums.phpfreaks.com/topic/165466-solved-creating-readable-varchar/ Share on other sites More sharing options...
ignace Posted July 10, 2009 Share Posted July 10, 2009 It is still there. Check your html to verify it, however html doesn't recognize \n therefor it is up to you to format it properly. <?php print nl2br("Hello all,\nI have the following\nA dog,\nA Cat"); ?> Link to comment https://forums.phpfreaks.com/topic/165466-solved-creating-readable-varchar/#findComment-872696 Share on other sites More sharing options...
NewbieBryan Posted July 10, 2009 Author Share Posted July 10, 2009 Great, tx Ignace, Looking at the raw data in the dB I see that it is displayed naturally (ie: as it was written) but I assume the /n and whatnot are "hidden" when viewing the PhpMyadmin but this is a great start. Next bit; When I pull the data to display I am using the following echo "<tr>"; echo "<td>" . $row['Comment'] . "</td>"; echo "<td>" . $row['Author'] . "</td>"; echo "</tr>"; That works great as is; but Can I now be "clever" and insert nl2br in there somewhere? Maybe: . $row[nl2br('Comment')] Link to comment https://forums.phpfreaks.com/topic/165466-solved-creating-readable-varchar/#findComment-872732 Share on other sites More sharing options...
ignace Posted July 10, 2009 Share Posted July 10, 2009 $row[nl2br('Comment')] Would be less clever You probably mean: nl2br($row['Comment']) And yes you could do that Link to comment https://forums.phpfreaks.com/topic/165466-solved-creating-readable-varchar/#findComment-872754 Share on other sites More sharing options...
NewbieBryan Posted July 10, 2009 Author Share Posted July 10, 2009 Worked like a charm, tx again Ignace - I really appretiate the assistance. Link to comment https://forums.phpfreaks.com/topic/165466-solved-creating-readable-varchar/#findComment-872807 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.