Reputation: 25
Hi is there any way to make <br>
working even there is htmlspecialchars
function.
My problem is when i put a text inside the function htmlspecialchars
there be no new lines even the text has new lines.
My code is like:
$text_val = "
this is a line
it is a new line
one more line
";
$final_text = str_replace("\n","<br>",$text_val);
$text = htmlspecialchars($final_text);
echo $text;
and result is like:
this is a line it is a new line one more line
But i want it like the first:
this is a line
it is a new line
one more line
thank you guys.
Upvotes: 2
Views: 145
Reputation: 16301
You're looking for the htmlspecialchars_decode()
function but using the htmlspecialchars()
function instead.
Replace this line:
$text = htmlspecialchars($final_text);
with this:
$text = htmlspecialchars_decode($final_text);
Upvotes: 1