Jump to content

PHP Searching a text file?


Padgoi

Recommended Posts

Ok, right now, it's just a file that displays a random line from a text file. Here is the current script:


$myfile = 'random1.txt';

if(file_exists($myfile))
{
$file = file($myfile);
$lines = count($file) - 1;
echo $file[rand(0, $lines)];
}
else
trigger_error('File ' . $myfile . ' does not exist', E_USER_ERROR);




Can anyone help me out with adding a search to it? I want people to be able to search their email address or password to see if they're in the text file. Can anyone help me with this, my php knowledge is very limited?  Thank you in advance.
Link to comment
https://forums.phpfreaks.com/topic/28472-php-searching-a-text-file/
Share on other sites

Ok, I have this to enter the thing the user is searching for:

<form action="page.php" method="post">
<fieldset>
<legend>Search Stolen Information</legend>
<label for="keyword">Email Address or Password:</label> <input type="text" id="keyword" name="search">

<input type="submit" value="Search">
</fieldset>
</form>

Now I just need the php script in page.php that actually searched the text file for the thing the user wants to search for.  Any help please?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.