note 38855 added to function.file-exists

From: Date: Fri, 09 Jan 2004 01:29:16 +0000
Subject: note 38855 added to function.file-exists
Groups: php.notes 
Request: Send a blank email to php-notes+get-63182@lists.php.net to get a copy of this message
Simple way to check a file, open, read and search the contents of a text file. Here sub folder is myphptxt. The codes were tested/deployed in IIS as well as Apachae win 2 ks/VPN and Apache on Solaris 8.0/IP. Text File James Bond Timothy Hunt Jose McDonald Barbe Fisher Manas Mukherjee HTML Client <html> <head> <title>file_exists.html</title> </head> <body> <form method="POST" action="file_exists.php"> <p><input type="text" name="agents_name" size="20"> <br><input type="submit" value="Submit" name="B1"> <input type="reset" value="Reset" name="B2"></p> </form> </body> </html> Server <?php # file_exists.php $read=($agents_name); $count =0; $filename="myphptxt/agents.txt"; # you may use a variable to hold the path. if (@!file_exists($filename)) { echo "oops! didn't find the file $filename"; } else { if (!$file_open = fopen($filename,"r")) { echo "oops! could open the file"; } else { echo" File found and working on the file. <br>"; while(@!feof($file_open)) { $count++; $line = fgets($file_open, 255); $line=(trim($line)); if ( $line == $read ){ echo "<b>Rated $count ! $line </b><BR>"; $match=$line;} } if (@$match ==""){ echo "Sorry No Match";} fclose($file_open); } } ?> my email : manaskmukherjee@frontiersoft.net ---- Manual Page -- http://www.php.net/manual/en/function.file-exists.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+38855 Delete -- http://master.php.net/manage/user-notes.php?action=delete+38855&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+38855&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#63182) next »