Home > Blockchain >  How do I line break while also disabling code being executed in textarea?
How do I line break while also disabling code being executed in textarea?

Time:04-13

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?

CodePudding user response:

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>";
  • Related