dave1950 Posted April 13, 2014 Share Posted April 13, 2014 I am a newbie to mysql and php and have inherited a mysql database with documents that appear to contain paragraph formatting based on viewing the actual data in the “SectionText” table while in phpMyAdmin. The table uses “longtext” type data format. When I display a document from the SectionText table on a web page, the paragraph formatting does not exist and it all runs together with no paragraphs. To display the document content after searching the database, I use this code: echo "<table border='1' width='600px'> <tr class=\"style3\"> <th>Text</th> "; while($row = mysql_fetch_array($result1)) { echo "<tr class=\"style2\">"; echo "<td style=\"width: 600px;\">" . $row['SectionText'] . "</td>"; echo "</tr>"; } echo "</table>"; I assume that I will want to modify the echo statement that displays the SectionText data, but have not been able to find anything on the web to help me get started in sorting this out. Any help would be greatly appreciated. - Dave Quote Link to comment https://forums.phpfreaks.com/topic/287743-retaining-paragraphs-in-displayed-data/ Share on other sites More sharing options...
trq Posted April 13, 2014 Share Posted April 13, 2014 nl2br might be sufficient enough for this task, or, if you want everything wrapped in <p></p> tags, try: echo "<td style=\"width: 600px;\"><p>" . preg_replace("/\r\n|\r|\n/", "</p><p>", $row['SectionText']) . "</p></td>"; Quote Link to comment https://forums.phpfreaks.com/topic/287743-retaining-paragraphs-in-displayed-data/#findComment-1476010 Share on other sites More sharing options...
Solution dave1950 Posted April 13, 2014 Author Solution Share Posted April 13, 2014 Thanks so much. That is exactly what I needed and I really appreciate that you provided two excellent options. Quote Link to comment https://forums.phpfreaks.com/topic/287743-retaining-paragraphs-in-displayed-data/#findComment-1476021 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.