0

I am creating a Tracking system using PHP. I have everything done, pretty much.

I have a system to create a file (XXXX-XXXX-XXXX.php) and writes the following code into it:

$content = file_get_contents("' . $_POST['id'] . '.txt"); echo $content;

So then, when someone accesses the tracking URL, it will get the contents of the text document created as well, and echo the content. That works fine, but the issue is showcasing line breaks.

TRACKING ID CREATED. 12/22/2018 AT 05:57:51 PM. THANKS FOR PURCHASING, TEST@GMAIL.COM

Testing.

New line?

This is the text document that the page is echoing.

TRACKING ID CREATED. 12/22/2018 AT 05:57:51 PM. THANKS FOR PURCHASING, TEST@GMAIL.COM Testing. New line? This is the page.

The line breaks aren't there. Not sure how to go about getting them to display.

  • you really should use a database for storage not a text tile –  Dec 22 '18 at 23:23
  • Instead of linking to images containing text, please type the text directly into your question. – Kresimir Dec 22 '18 at 23:35
  • @tim It's for my personal use, with minimal projects. If I need to expand with more projects, then yeah, but right now, learning MySQL and how to implement properly for such a small project isn't needed. – Landon Crabtree Dec 22 '18 at 23:44
  • Since I cannot post the answer, I'll post here: Please just add `header('Content-Type: TEXT');` before echo'ing. – Beyondo Apr 03 '22 at 20:23

1 Answers1

4

You will want to encode your plain text as HTML and convert your newlines to <br> tags with nl2br

nl2br(htmlentities($content));
blockhead
  • 463
  • 2
  • 5