Hello.

There is a need to calculate a checksum for each line of a text file. The result must be recorded in a separate file.

For example, there is a data.txt file which contains the following text:

Кресло Тумба приставная Портофино Тумба под аппаратуру Бумага цветная Помпа для воды Корзина для мусора Линейка металлическая Точилка 

It is necessary to create a data_crc32 file next to which will contain on each line the corresponding checksum crc32:

 38bb8239 27c01629 9446ea58 946f4d36 7b6976f8 575f06ea eb3838f1 e65783ac e432918b 

I would like to implement this solution in php

Closed due to the fact that the essence of the question is incomprehensible by the participants: Vladimir Martyanov , user194374, Alex , Kromster , Denis 19 December '16 at 6:42 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

  • And what prevented you from entering two queries in google "php file" and "php crc32" of these two functions and a little bit of logic will allow you to solve the problem - Mike
  • I don’t understand - what prevented commentators from passing by, if they didn’t like the question? This service exists so that some people can help others. - Miron
  • 2
    @Miron, a small clarification for the correct perception of the purpose of the existence of this site: 1. this is the knowledge base for programmers. 2. the same “question + answer (s)” pair, thanks to search engines, can help tens / hundreds / thousands / etc. programmers. 3. And the fact of concrete assistance to a concrete questioner on the part of a concrete respondent is only a single particular case, so to speak, “a pleasant side effect”. // the foregoing does not cancel the absolute uselessness (for those dozens / hundreds / thousands of programmers), for example, the first comment (from Vladimir Martyanov). - aleksandr barakin

1 answer 1

Below is the implementation and detailed comments, which line does what. If you want to learn PHP, you can see in detail the information in Russian for each function, adding its name after the site address, for example: http://php.net/fopen

 <?php $fp_read = fopen("data.txt", "r"); // Открываем файл на чтение $fp_write = fopen("data_crc32.txt", "w"); // Открываем файл на запись while (!feof($fp_read)) { $data = fgets($fp_read, 4096); // Получаем строку из файла data.txt $data = trim($data); // Очищаем строку от лишних пробелов и символов перевода коретки: \n, \r\n, etc $data = crc32($data); // Получаем crc32 $data = $data."\n"; // Добавляем символ перевода каретки или \r\n - если Виндовс fwrite($fp_write, $data); // Записываем результат в файл data_crc32.txt - построчно //echo crc32($buffer).' '; } fclose($fp_read); // Закрываем файл fclose($fp_write); // Закрываем файл ?> 
  • Thanks for answering everyone. I have long programmed php programs for myself. For more than 5 years I have not dealt with them - everything is forgotten! - Wexus