PHP: Displaying Paragraphs from MySQL Database

Let the image explain:
Without this function, the browser won't read the paragraph properly from MySQL Database. The new line will be ignored as shown in the image above (blue border).
In order to display the paragraph properly we will use this PHP Function:

Definition and Usage
The nl2br() function inserts HTML line breaks (<br> or <br />) in front of each newline (\n) in a string.
The function above will achieve the "red border" as shown in the image.
echo "<td>LEARNING OBJECTIVES (LO)</td>";
echo nl2br("<td>" . $row['learning_objective'] . "</td>");
echo "</tr>";

Just enclose the "value" with nl2br as shown above.

That's it! Comment below for any clarification.

Popular posts from this blog

Add/Subtract Single Digit Number in Assembly Language

Set table width to 100% on PDF export in Datatables

A Better Archive Page for Blogger