I would like to display a txt file using JS or PHP respecting line break

Asked

Viewed 31 times

-1

I tried included and require, but they do not respect the line break.

I want to print the file information inside a <p>, study-only.

  • John better describe examples, because the question can be marked as pending

  • Place the content inside the <pre></pre>

1 answer

1


Using a ready-made solution

Replace the tag <p> by the tag <pre>, so the page will respect line breaks, if the text is not formatted as you want, just set a style to tag <pre>.

pre{
  font-family: Arial, Helvetica Neue, Helvetica, sans-serif;
}
<pre>
Texto com quebra de linha aqui
Texto com quebra de linha aqui
Texto com quebra de linha aqui
Texto com quebra de linha aqui
Texto com quebra de linha aqui
Texto com quebra de linha aqui
</pre>

Continue using the p tag

You can make this same tag effect <pre> using the css.

p{
  white-space: pre;
}
<p>
Texto com quebra de linha aqui
Texto com quebra de linha aqui
Texto com quebra de linha aqui
Texto com quebra de linha aqui
Texto com quebra de linha aqui
Texto com quebra de linha aqui
</p>

Just arrow the following rule to your css style

white-space: pre;
  • 1

    Thank you very much, it was a very simple solution, I thought I needed to add some more commands in php, but only the tag solved. <pre style="color: red; font-size: 16px;">&#xA; <?php&#xA; include 'text.txt';&#xA; ?>&#xA; </pre>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.