I am trying to store a formatted text paragraph in a MySQL database longtext field. I would like to use the fields value in an echo statement to display the paragraph on a web page.
Despite multiple different approaches, my stored text is never displayed with the formatting intact. I assume this problem has two parts. First the formatting of the text I am pasting into my longtext field (I am using navicat to visually edit the mysql tables/records). Secondly, my php code to dynamically display the lontext field's value may be incorrect.
To address my first question:
I have tried pasting text directly from MS word and also from notepad, as well as html formatted text from Adobe Dreamweaver. None has worked. Can someone confirm the correct text format I must use when storing text using longtext (plain text, etc.) and also whether long text is the correct field type to use? (I will be storing long essays).
To address my second question, I have tried reformatting the field's value upon display using the following code snippets:
Code: Select all
<?php echo $row_Recordset1['Bio']; ?>
<?php print nl2br(str_replace(" "," ",stripslashes($row_Recordset1['Bio']))); ?>
<?php
$text= htmlspecialchars(htmlentities ($row_Recordset1['Bio']));
echo $text;
?>
<?php $text2 = $row_Recordset1['Bio'];
$text2 = str_replace("\n", "<br>", $text2);
echo $text2;
?>