https://dev.webpages.dk/  
 
PHP Create and convert textfile
How to create a textfile and write to it, coverting newline's:

To convert 'newlines' into HTML breaks (<BR />), we can use the simple command; nl2br($string);

This will show the text with the newlines or linebreaks preserved when showing in HTML.

Also be sure to read the pages about stripping HTML tags.
And htmlspecialchars, and the second part of this;
htmlspecialchars_decode

 Create and convert textfile

How to create a textfile and write to it, coverting newline's

If we want to read the 'file.txt' that we created in the posting 'How to create a textfile and write to it', we will notice that the newlines that we inserted in the string, written to the file does not show in the webbrowser. So what can we do about that?

PHP comes with a small solution to that problem, it is called 'nl2br' (newline to break), it will convert the newline into a HTML break <BR />. Here I show how to do this. It is very simple, we just add one line, the one that is highlighted in this snippet. Then we write HTML breaks instead of newlines.

 PHP

<?php
    $String = "Hello World!\n\nThis is a test in creating a textfile, and writing to it."; 
    $String = nl2br($String);

    $mytextfile = fopen("file.txt", "a") or die("An error occurred. Send webmaster a message"); 

    fwrite($mytextfile, $String); 
    fclose($mytextfile); 

    echo 'Super, you have created a file'; 
?>

This was a way to handle linebreaks.

Icons made by Freepik from www.flaticon.com How to create a textfile and write to it, coverting newline's using 'nl2br()'
01:20:39