In the following code when I echo the text in “Details” column after retrieving the record from mySQL database, I want it to echo line break (< br/ >) for all the ¶ (pilcrows) in the database record.
I know I can use nl2br() to replace all \n to <br/>, but first I need to replace all ¶ (pilcrows) to \n. How can I do it? Here is my code:
<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("my_db", $con);
$result = mysql_query("SELECT * FROM Persons");
while($row = mysql_fetch_array($result))
{
echo $row['Details'];
}
mysql_close($con);
?>
Simply use something like
$row['Details'] = str_replace("¶", "\n", $row['Details']);. That will change every pilcrow into a newline (as long as the pilcrow isn’t encoded, of course).