note 38855 deleted from function.file-exists by nlopess
| From: | nlopess@php.net | Date: | Fri, 09 Jan 2004 14:17:10 +0000 |
| Subject: | note 38855 deleted from function.file-exists by nlopess | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-63196@lists.php.net to get a copy of this message | ||
Note Submitter: manaskmukherjee@frontiersoft.net
----
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