PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY combination (Virtual web hosting)
PHP SOLUTIONS: DYNAMIC WEB DESIGN MADE EASY combination with feof() to read right through to the end of the file. This is done by replacing this line $contents = fread($file, filesize($filename)); with this (the full script is in fopen_readloop.php) // create variable to store the contents $contents = ‘’; // loop through each line until end of file while (!feof($file)) { // retrieve next line, and add to $contents $contents .= fgets($file); } The while loop uses fgets() to retrieve the contents of the file one line at a time !feof($file) is the same as saying until the end of $file and stores them in $contents. It doesn t take a genius to see that both methods are more long-winded than using file() or file_get_contents(). However, you need to use either fread() or fgets() if you want to read the contents of a file at the same time as writing to it. Replacing content with fopen() The first of the write-only modes (w) deletes any existing content in a file, so it s useful for working with files that need to be updated frequently. You can test the w mode with fopen_write.php, which has the following PHP code above the DOCTYPE declaration: There s no need to use a loop this time: you re just writing the value of $contents to the opened file. The function fwrite() takes two arguments: the reference to the file and whatever you want to write to it. In other books or scripts on the Internet, you may come across fputs() instead of fwrite(). The two functions are identical: fputs() is a synonym for fwrite().
Go visit our java server pages services for a reliable, lowcost webhost to satisfy all your needs.