Jump to content

Scaning A Txt File With Php


Frieling

Recommended Posts

Alright,I cannot figure out how i can scan a txt file using PHP. For example:Banlist.txt contents:vcfdasacdjaskbcdasocbdhas GeorgeEndvcfdasacdjaskbcdasocbdhas = GuidGeorge = NameNow i don't even know how to get started. Any help?P.S. I am finally back.

Link to comment
Share on other sites

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 comment
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 comment
Share on other sites

Alright,Well i am trying to figure out how to do it do it via file system way. I started with a simple form with the text box of the value of query. How can i use the file system to search it line by line, and then it gets the info that was entered into the text box?

Link to comment
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 comment
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 comment
Share on other sites

Archived

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

×
×
  • Create New...