1

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?

Tecior
  • 21
  • 6

1 Answers1

0

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>";
Barmar
  • 741,623
  • 53
  • 500
  • 612