I want to wite to a text file at the inputed text position using PHP. I tried using fseek to point the wite position to the inputed number, but it saves as an empty file instead.
<?php
$testData = "testdata";
$testPosition = 3;
$fileReference = fopen("test.txt", "w");
fseek($fileReference, $testPosition);
fwrite($fileReference, $testData);
fclose($fileReference);
?>
How would I get the script to wite to the text file at the specified position correctly?
The w flag only allows for writing to a file. Try replacing the w flag with a r+
flag. This will allow for read/write to a file without truncating the file. the read /write is needed to allows you to go search for your caret and write to where it is. for more information on the fopen function please see php.net: fopen()