Jump to content

Scaning A Txt File With Php


Recommended Posts

If you want, you may instead turn the file into an array, and then loop over the array. You can do that with file().In general, PHP has quite a few filesystem functions. Depending on what you want to do with the file, you may use one or more of them.

Link to post
Share on other sites
Alrightt,What about using a XML Parser? But if we did that, how would i be able to put stuff like i showed in there automaticly.
DOM (reccomended) or SimpleXML (useful if you're too lazy, or if your XML is indeed really simple).
Link to post
Share on other sites
  • 5 months later...

sorry to bring up a old post, but i am back at it again.this is what i have so far:

<?phpfunction main(){	echo '<form action="index.php?op=search" method="get">';	echo 'Enter a 32 Digit GUID<input type="text" name="guid">';	echo '<input type="submit" name="go" value="Search">';}function search(){global $guid;	$file = 'banlist.txt';	$read = fopen($file, "r");		if(!$file){		echo 'File does not exist';	} else {			}}switch($op){	default: main(); break;	case 'search': search(); break;}?>

Now how can i check it against the banlist.txt to see whether the entered string is in that file. i keep getting confused on that part. :)

Link to post
Share on other sites

1. You are not using fopen() correctly.2. But that doesn't matter, because file_get_contents is a better way to read your file anyway. It will put the file contents into one long string.3. Now you can use strpos to see if your search string is in the file string. (The manual explains how to distinguish between 0 and FALSE; be sure you take that into consideration.)4. You have not clearly explained what form the search string will take. Let's say banlist.txt looks like this:dogcathorseIf your user enters "horse", finding a match will be very easy. But if your user enters "I like horses" or "catheter", you have a different set of problems to solve.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...