Jump to content

Reading and writing to specific parts of .txt


mathiasppc

Recommended Posts

Is this possible? Could the following code be replaced with one .txt consisting of two digits?

 

$myFile = "offerrotation.txt";
$myFile2 = "lprotation.txt";

$fh = @fopen($myFile, 'r');
$offerNumber = @fread($fh, 5);
@fclose($fh);

$fh = @fopen($myFile2, 'r');
$lpNumber = @fread($fh, 5);
@fclose($fh);

 

Many thanks

If you write them both at the same time, you can just concatenate them within a string and use the new-line character ("\n") to put them on different lines:

 

$new_rotation = $new_offer . "\n" . $new_lp;
file_put_contents('rotation.txt', $new_rotation);

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.