I store some data into mysql database when someone enter a data hi put enter for a newline this newline is store it into database
when i want to read this information from database the output be like that
test
xxx....
How can i read the like a newline what i mean is the output be like that
test
xxxx
I store the input like that
$desc=strip_tags(mysqli_real_escape_string($conn,$_POST['desc']));
I use nl2br()
and htmlentities()
and it didn't give me the result i want
How can i solve this problem??!!
You can use nl2br()
with the optional parameter set to false
. See the docs.
echo nl2br("test
xxx....", false); //Output: test<br/>xxx....
If you really want to get rid of the , then you need to remove it.
$tempArr = array();
foreach(explode("
", "test
xxx....") as $line)
{
$tempArr[] = trim($line); // removes all linebreaks and whitespaces, even
}
$text = implode("
", $tempArr);
echo nl2br($text);