I am trying to get all the rows from my MySQL database using the following code:
$sql = "SELECT * FROM myTable";
$result = $conn->query($sql);
while($row = $result->fetch_assoc()) {
$output[]=$row;
}
echo json_encode($output);
My question is, How to preserve the line breaks using this code? I can preserve line breaks using nl2br() when I need a particular string for example
nl2br($_row['fieldName']);
but I want to know How can I use the same nl2br() when fetching the result in an array?
I have referred this question as well but this explains just for a single string not the array.
If there is no way of doing it, please suggest me some other way of doing it.
or
inserted before all newlines (\r\n, \n\r, \n and \r).** – mickmackusa Jun 22 '20 at 03:33