There is a plain text document t.txt. It contains 3 numbers. How to use PHP to get from the file number. And perform a loop. Code example

<?php $file = fopen("t.txt", "r+"); $data = fgets($file); $array = explode(' ', $data); list($value1, $value2, $value3) = $data; $i = 1; while ($i <= value3) { $result =''; if ($i%$value1==0) { $result .='F';} if ($i%$$value2==0) { $result .='B';} if (!$result) { $result = $i;} $i++; } $test = fwrite($file, $result); if ($test) echo 'Данные в файл успешно занесены.'; else echo 'Ошибка при записи в файл.'; fclose($file); 

T.txt content

 1 2 20 
  • I did not understand what you need to get in the end? overwrite file? to add? just iterate the data? - StereoFlo pm
  • It is necessary to take numbers from a file and substitute value1 = 1, value2 = 2, value3 = 20 in a cycle - Vladislav Ilichov

1 answer 1

The simplest example. We get the data from the file.

  $data = file('file/path/t.txt'); 

Separate the data.

  $values = explode(' ', $data); list($value1, $value2, $value3) = $values 

Perform a cycle and actions. The cycle will go from 0 to $value3 Namely, up to and including 20.

  for($i = 0; $i <= $value3; $i++) { //тут код }