'How do I line break while also disabling code being executed in textarea?
I have PHP set up for a textarea that prints text from a directory to separate divs.
<?php
$content = implode("<br /><hr class='separator'>",array_map(function ($v) {
return file_get_contents($v);
}, glob(__DIR__ . "/posts/*.txt")));
echo '<div>';
// echo htmlentities($content);
echo '</div>';
?>
When I use htmlentities (commented out above), it disables my line break (and also my hr separator code).
I tried using \n but it also doesn't work.
How do I keep my <br /><hr class='separator'> code but still use htmlentities?
Solution 1:[1]
Call htmlentities() before inserting the HTML separators.
$content = implode("<br /><hr class='separator'>",array_map(function ($v) {
return htmlentities(file_get_contents($v));
}, glob(__DIR__ . "/posts/*.txt")));
echo "<div>$content</div>";
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Barmar |
