Hello. I understand the wisdom of working with files in php. In the process I came across such a problem: I open the file with fopen, write it with fwrite, read it as strings with the help of fgets and output everything to the screen. Everything works great. But I came across a problem when you need to check whether there is something in the file (orders, for example) and, if there are no order lines in the file, display "No orders", otherwise display the contents. I thought everything was simple, it turned out that not everything is so obvious to me. Help, please, satisfy curiosity. Thank.
Code:
<?php //открываем файл для записи (если его нет - создается автоматически @$fp = fopen("$DOCUMENT_ROOT/../vovan/orders/orders.txt", 'r'); if (!$fp) { echo "<p><strong>Какие-то проблемы с файлом? А если найду?<strong></p>"; exit; } while (!feof($fp)) { $order = fgets($fp, 999); echo $order . "<br /><br />"; } fclose($fp); ?>