To write to the txt file:
<?php $file = 'file.txt'; $data = 'this is your string to write'; file_put_contents($file, $data); ?>
To display the contents of this file somewhere on the page (remember that the page must have a .php extension for php to work):
<?php
EDIT:
To answer another question from the comments:
When saving your data to a file, the source code is fine, just use this. Another code appears when the contents of the file are echoed, so it will now look like this:
<?php $contents = file_get_contents('file.txt'); $contents = explode("\n", $contents); foreach($contents as $line){ $firstComma = (strpos($line, ","))+1; $newLine = substr($line, $firstComma); echo $newLine."\n"; } ?>
Try it like this. I do not have my server here, so I can not test it, but I believe that I was not mistaken there.
Richard Rodriguez
source share