Re: Re[4]: [PHP] Searching for text in a file
Richard, Then you need to use something like "explode()" to get only the part you want. e.g. If the file is delimited by spaces, then have something like this: $fd = fopen ("virtusertable", "r"); $variable= "[EMAIL PROTECTED]"; $count = 1; while(feof($fd) == false) { $line_text = fgets($fd, 2048); $strings = explode(" ", $line_text);<--- Splits the line at every space into an array of string if ($variable == trim($strings[0])) { echo "Match at line number $count"; break; } ++$count; } If the file is tab delimited, you will need: $strings = explode("\t", $line_text); > Hello Kelly, > Your right the script does work but my problem is this > the file I am searching looks like this below. > And if I search on [EMAIL PROTECTED] alone it does not find it but > if I search on [EMAIL PROTECTED] yourns it finds it. I need it > to find just the email address not the stuff after it. > > > [EMAIL PROTECTED] yourns > [EMAIL PROTECTED] root > [EMAIL PROTECTED] majordomo_site1 > [EMAIL PROTECTED] owner-majordomo_site15 > [EMAIL PROTECTED] sys > > > Monday, September 10, 2001, 1:26:44 AM, you wrote: > > Kelly Barrett> Richard, > Kelly Barrett> I just put together a script using that code exactly, and it worked. > > Kelly Barrett> All I can say is make sure that what you are searching for is actually in > Kelly Barrett> the file you are searching. > > Kelly Barrett> Remember that the string you are searching for needs to match the entire > Kelly Barrett> contents of the line, not just a substring of the line. > > Kelly Barrett> Try some simple tests that you know are sure to work. i.e. Make a > Kelly Barrett> virtusertable file that is just a couple of lines. > > >> Hello Kelly, > >> Yes I noticed the variable after I sent the message > >> Now I have it like this. But If I add something that is in the file it > >> does not find it. > >> > >> $fd = fopen ("virtusertable", "r"); > >> $variable= "[EMAIL PROTECTED]"; > >>$count = 1; > >> while(feof($fd) == false) { > >> $line_text = fgets($fd, 2048); > >> if ($variable == trim($line_text)) { > >>echo "Match at line number $count"; > >> break; > >> } > >> ++$count; > >> } > >> > >> > >> Monday, September 10, 2001, 12:39:15 AM, you wrote: > >> > >> Kelly Barrett> Hi Richard, > >> Kelly Barrett> First, I think it should be: > >> Kelly Barrett> $variable = "[EMAIL PROTECTED]"; > >> Kelly Barrett> instead of: > >> >> $line_text= "[EMAIL PROTECTED]"; > >> > >> Kelly Barrett> as you overwrite $line_text with your fgets. > >> > >> Kelly Barrett> Also: > >> >> if ($variable = trim($line_text)) { > >> Kelly Barrett> Should be: > >> Kelly Barrett> if ($variable == trim($line_text)) { > >> > >> Kelly Barrett> Otherwise you are doing an assignment, which will > >> always be true. > >> > >> Kelly Barrett> Finally, your while loop should probably be: > >> Kelly Barrett> while(feof($fd) == false) { > >> Kelly Barrett> $line_text = fgets($fd, 2048); > >> > >> Kelly Barrett> Because fgets returns EOF at the end of a file, > >> not necessarily false (I > >> Kelly Barrett> THINK EOF currently is false, though theoretically > >> EOF could change to any > >> Kelly Barrett> value). > >> > >> Kelly Barrett> Cheers, > >> Kelly Barrett> Kelly. > >> > >> >> -Original Message- > >> >> From: Richard Kurth [mailto:[EMAIL PROTECTED]] > >> >> Sent: Monday, 10 September 2001 5:12 PM > >> >> To: php > >> >> Subject: [PHP] Searching for text in a file > >> >> > >> >> > >> >> I am having a problem with searching through a file for a curtain > >> >> text. Like the text below [EMAIL PROTECTED] does not exists in the file > >> >> but when I run this it gives me a Match at line number. > >> >> I need to run three or four names at a time through this script > >> >> to see if they are already there. But it does not seam to work. > >> >> And I can not figure out way. A small sample of the file i
Re[4]: [PHP] Searching for text in a file
Hello Kelly, Your right the script does work but my problem is this the file I am searching looks like this below. And if I search on [EMAIL PROTECTED] alone it does not find it but if I search on [EMAIL PROTECTED] yourns it finds it. I need it to find just the email address not the stuff after it. [EMAIL PROTECTED] yourns [EMAIL PROTECTED] root [EMAIL PROTECTED] majordomo_site1 [EMAIL PROTECTED] owner-majordomo_site15 [EMAIL PROTECTED] sys Monday, September 10, 2001, 1:26:44 AM, you wrote: Kelly Barrett> Richard, Kelly Barrett> I just put together a script using that code exactly, and it worked. Kelly Barrett> All I can say is make sure that what you are searching for is actually in Kelly Barrett> the file you are searching. Kelly Barrett> Remember that the string you are searching for needs to match the entire Kelly Barrett> contents of the line, not just a substring of the line. Kelly Barrett> Try some simple tests that you know are sure to work. i.e. Make a Kelly Barrett> virtusertable file that is just a couple of lines. >> Hello Kelly, >> Yes I noticed the variable after I sent the message >> Now I have it like this. But If I add something that is in the file it >> does not find it. >> >> $fd = fopen ("virtusertable", "r"); >> $variable= "[EMAIL PROTECTED]"; >>$count = 1; >> while(feof($fd) == false) { >> $line_text = fgets($fd, 2048); >> if ($variable == trim($line_text)) { >>echo "Match at line number $count"; >> break; >> } >> ++$count; >> } >> >> >> Monday, September 10, 2001, 12:39:15 AM, you wrote: >> >> Kelly Barrett> Hi Richard, >> Kelly Barrett> First, I think it should be: >> Kelly Barrett> $variable = "[EMAIL PROTECTED]"; >> Kelly Barrett> instead of: >> >> $line_text= "[EMAIL PROTECTED]"; >> >> Kelly Barrett> as you overwrite $line_text with your fgets. >> >> Kelly Barrett> Also: >> >> if ($variable = trim($line_text)) { >> Kelly Barrett> Should be: >> Kelly Barrett> if ($variable == trim($line_text)) { >> >> Kelly Barrett> Otherwise you are doing an assignment, which will >> always be true. >> >> Kelly Barrett> Finally, your while loop should probably be: >> Kelly Barrett> while(feof($fd) == false) { >> Kelly Barrett> $line_text = fgets($fd, 2048); >> >> Kelly Barrett> Because fgets returns EOF at the end of a file, >> not necessarily false (I >> Kelly Barrett> THINK EOF currently is false, though theoretically >> EOF could change to any >> Kelly Barrett> value). >> >> Kelly Barrett> Cheers, >> Kelly Barrett> Kelly. >> >> >> -Original Message- >> >> From: Richard Kurth [mailto:[EMAIL PROTECTED]] >> >> Sent: Monday, 10 September 2001 5:12 PM >> >> To: php >> >> Subject: [PHP] Searching for text in a file >> >> >> >> >> >> I am having a problem with searching through a file for a curtain >> >> text. Like the text below [EMAIL PROTECTED] does not exists in the file >> >> but when I run this it gives me a Match at line number. >> >> I need to run three or four names at a time through this script >> >> to see if they are already there. But it does not seam to work. >> >> And I can not figure out way. A small sample of the file is below. >> >> >> >> $fd = fopen ("virtusertable", "r"); >> >> $line_text= "[EMAIL PROTECTED]"; >> >>$count = 1; >> >> while ($line_text = fgets($fd, 2048)) { >> >> if ($variable = trim($line_text)) { >> >>echo "Match at line number $count"; >> >> break; >> >> } >> >> ++$count; >> >> } >> >> >> >> >> >> [EMAIL PROTECTED] >> >> [EMAIL PROTECTED] >> >> [EMAIL PROTECTED] >> >> [EMAIL PROTECTED] >> >> [EMAIL PROTECTED] >> >> [EMAIL PROTECTED] >> >> [EMAIL PROTECTED] >> >> [EMAIL PROTECTED] >> >> [EMAIL PROTECTED] >> >> [EMAIL PROTECTED] >> >> [EMAIL PROTECTED] >> >> [EMAIL PROTECTED] >> >> [EMAIL PROTECTED] >> >> [EMAIL PROTECTED] >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> Best regards, >> >> Richard >> >> mailto:[EMAIL PROTECTED] >> >> >> >> >> >> -- >> >> PHP General Mailing List (http://www.php.net/) >> >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> To contact the list administrators, e-mail: >> [EMAIL PROTECTED] >> >> >> >> >> >> >> >> >> >> -- >> Best regards, >> Richard >> mailto:[EMAIL PROTECTED] >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> To contact the list administrators, e-mail: [EMAIL PROTECTED] >> >> -- Best regards, Richard mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: Re[2]: [PHP] Searching for text in a file
Richard, I just put together a script using that code exactly, and it worked. All I can say is make sure that what you are searching for is actually in the file you are searching. Remember that the string you are searching for needs to match the entire contents of the line, not just a substring of the line. Try some simple tests that you know are sure to work. i.e. Make a virtusertable file that is just a couple of lines. > Hello Kelly, > Yes I noticed the variable after I sent the message > Now I have it like this. But If I add something that is in the file it > does not find it. > > $fd = fopen ("virtusertable", "r"); > $variable= "[EMAIL PROTECTED]"; >$count = 1; > while(feof($fd) == false) { > $line_text = fgets($fd, 2048); > if ($variable == trim($line_text)) { >echo "Match at line number $count"; > break; > } > ++$count; > } > > > Monday, September 10, 2001, 12:39:15 AM, you wrote: > > Kelly Barrett> Hi Richard, > Kelly Barrett> First, I think it should be: > Kelly Barrett> $variable = "[EMAIL PROTECTED]"; > Kelly Barrett> instead of: > >> $line_text= "[EMAIL PROTECTED]"; > > Kelly Barrett> as you overwrite $line_text with your fgets. > > Kelly Barrett> Also: > >> if ($variable = trim($line_text)) { > Kelly Barrett> Should be: > Kelly Barrett> if ($variable == trim($line_text)) { > > Kelly Barrett> Otherwise you are doing an assignment, which will > always be true. > > Kelly Barrett> Finally, your while loop should probably be: > Kelly Barrett> while(feof($fd) == false) { > Kelly Barrett> $line_text = fgets($fd, 2048); > > Kelly Barrett> Because fgets returns EOF at the end of a file, > not necessarily false (I > Kelly Barrett> THINK EOF currently is false, though theoretically > EOF could change to any > Kelly Barrett> value). > > Kelly Barrett> Cheers, > Kelly Barrett> Kelly. > > >> -Original Message- > >> From: Richard Kurth [mailto:[EMAIL PROTECTED]] > >> Sent: Monday, 10 September 2001 5:12 PM > >> To: php > >> Subject: [PHP] Searching for text in a file > >> > >> > >> I am having a problem with searching through a file for a curtain > >> text. Like the text below [EMAIL PROTECTED] does not exists in the file > >> but when I run this it gives me a Match at line number. > >> I need to run three or four names at a time through this script > >> to see if they are already there. But it does not seam to work. > >> And I can not figure out way. A small sample of the file is below. > >> > >> $fd = fopen ("virtusertable", "r"); > >> $line_text= "[EMAIL PROTECTED]"; > >>$count = 1; > >> while ($line_text = fgets($fd, 2048)) { > >> if ($variable = trim($line_text)) { > >>echo "Match at line number $count"; > >> break; > >> } > >> ++$count; > >> } > >> > >> > >> [EMAIL PROTECTED] > >> [EMAIL PROTECTED] > >> [EMAIL PROTECTED] > >> [EMAIL PROTECTED] > >> [EMAIL PROTECTED] > >> [EMAIL PROTECTED] > >> [EMAIL PROTECTED] > >> [EMAIL PROTECTED] > >> [EMAIL PROTECTED] > >> [EMAIL PROTECTED] > >> [EMAIL PROTECTED] > >> [EMAIL PROTECTED] > >> [EMAIL PROTECTED] > >> [EMAIL PROTECTED] > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> > >> Best regards, > >> Richard > >> mailto:[EMAIL PROTECTED] > >> > >> > >> -- > >> PHP General Mailing List (http://www.php.net/) > >> To unsubscribe, e-mail: [EMAIL PROTECTED] > >> For additional commands, e-mail: [EMAIL PROTECTED] > >> To contact the list administrators, e-mail: > [EMAIL PROTECTED] > >> > >> > > > > > > -- > Best regards, > Richard > mailto:[EMAIL PROTECTED] > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re[2]: [PHP] Searching for text in a file
Hello Kelly, Yes I noticed the variable after I sent the message Now I have it like this. But If I add something that is in the file it does not find it. $fd = fopen ("virtusertable", "r"); $variable= "[EMAIL PROTECTED]"; $count = 1; while(feof($fd) == false) { $line_text = fgets($fd, 2048); if ($variable == trim($line_text)) { echo "Match at line number $count"; break; } ++$count; } Monday, September 10, 2001, 12:39:15 AM, you wrote: Kelly Barrett> Hi Richard, Kelly Barrett> First, I think it should be: Kelly Barrett> $variable = "[EMAIL PROTECTED]"; Kelly Barrett> instead of: >> $line_text= "[EMAIL PROTECTED]"; Kelly Barrett> as you overwrite $line_text with your fgets. Kelly Barrett> Also: >> if ($variable = trim($line_text)) { Kelly Barrett> Should be: Kelly Barrett> if ($variable == trim($line_text)) { Kelly Barrett> Otherwise you are doing an assignment, which will always be true. Kelly Barrett> Finally, your while loop should probably be: Kelly Barrett> while(feof($fd) == false) { Kelly Barrett> $line_text = fgets($fd, 2048); Kelly Barrett> Because fgets returns EOF at the end of a file, not necessarily false (I Kelly Barrett> THINK EOF currently is false, though theoretically EOF could change to any Kelly Barrett> value). Kelly Barrett> Cheers, Kelly Barrett> Kelly. >> -Original Message- >> From: Richard Kurth [mailto:[EMAIL PROTECTED]] >> Sent: Monday, 10 September 2001 5:12 PM >> To: php >> Subject: [PHP] Searching for text in a file >> >> >> I am having a problem with searching through a file for a curtain >> text. Like the text below [EMAIL PROTECTED] does not exists in the file >> but when I run this it gives me a Match at line number. >> I need to run three or four names at a time through this script >> to see if they are already there. But it does not seam to work. >> And I can not figure out way. A small sample of the file is below. >> >> $fd = fopen ("virtusertable", "r"); >> $line_text= "[EMAIL PROTECTED]"; >>$count = 1; >> while ($line_text = fgets($fd, 2048)) { >> if ($variable = trim($line_text)) { >>echo "Match at line number $count"; >> break; >> } >> ++$count; >> } >> >> >> [EMAIL PROTECTED] >> [EMAIL PROTECTED] >> [EMAIL PROTECTED] >> [EMAIL PROTECTED] >> [EMAIL PROTECTED] >> [EMAIL PROTECTED] >> [EMAIL PROTECTED] >> [EMAIL PROTECTED] >> [EMAIL PROTECTED] >> [EMAIL PROTECTED] >> [EMAIL PROTECTED] >> [EMAIL PROTECTED] >> [EMAIL PROTECTED] >> [EMAIL PROTECTED] >> >> >> >> >> >> >> >> >> >> >> >> Best regards, >> Richard >> mailto:[EMAIL PROTECTED] >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> To contact the list administrators, e-mail: [EMAIL PROTECTED] >> >> -- Best regards, Richard mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP] Searching for text in a file
Hi Richard, First, I think it should be: $variable = "[EMAIL PROTECTED]"; instead of: > $line_text= "[EMAIL PROTECTED]"; as you overwrite $line_text with your fgets. Also: > if ($variable = trim($line_text)) { Should be: if ($variable == trim($line_text)) { Otherwise you are doing an assignment, which will always be true. Finally, your while loop should probably be: while(feof($fd) == false) { $line_text = fgets($fd, 2048); Because fgets returns EOF at the end of a file, not necessarily false (I THINK EOF currently is false, though theoretically EOF could change to any value). Cheers, Kelly. > -Original Message- > From: Richard Kurth [mailto:[EMAIL PROTECTED]] > Sent: Monday, 10 September 2001 5:12 PM > To: php > Subject: [PHP] Searching for text in a file > > > I am having a problem with searching through a file for a curtain > text. Like the text below [EMAIL PROTECTED] does not exists in the file > but when I run this it gives me a Match at line number. > I need to run three or four names at a time through this script > to see if they are already there. But it does not seam to work. > And I can not figure out way. A small sample of the file is below. > > $fd = fopen ("virtusertable", "r"); > $line_text= "[EMAIL PROTECTED]"; >$count = 1; > while ($line_text = fgets($fd, 2048)) { > if ($variable = trim($line_text)) { >echo "Match at line number $count"; > break; > } > ++$count; > } > > > [EMAIL PROTECTED] > [EMAIL PROTECTED] > [EMAIL PROTECTED] > [EMAIL PROTECTED] > [EMAIL PROTECTED] > [EMAIL PROTECTED] > [EMAIL PROTECTED] > [EMAIL PROTECTED] > [EMAIL PROTECTED] > [EMAIL PROTECTED] > [EMAIL PROTECTED] > [EMAIL PROTECTED] > [EMAIL PROTECTED] > [EMAIL PROTECTED] > > > > > > > > > > > > Best regards, > Richard > mailto:[EMAIL PROTECTED] > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > To contact the list administrators, e-mail: [EMAIL PROTECTED] > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] Searching for text in a file
On Mon, 10 Sep 2001 16:41, Richard Kurth wrote: > I am having a problem with searching through a file for a curtain > text. Like the text below [EMAIL PROTECTED] does not exists in the file > but when I run this it gives me a Match at line number. > I need to run three or four names at a time through this script > to see if they are already there. But it does not seam to work. > And I can not figure out way. A small sample of the file is below. > > $fd = fopen ("virtusertable", "r"); > $line_text= "[EMAIL PROTECTED]"; >$count = 1; > while ($line_text = fgets($fd, 2048)) { > if ($variable = trim($line_text)) { You are assigning here - use == for comparison. >echo "Match at line number $count"; > break; > } > ++$count; > } > -- David Robley Techno-JoaT, Web Maintainer, Mail List Admin, etc CENTRE FOR INJURY STUDIES Flinders University, SOUTH AUSTRALIA Figures won't lie, but liars will figure. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Searching for text in a file
I am having a problem with searching through a file for a curtain text. Like the text below [EMAIL PROTECTED] does not exists in the file but when I run this it gives me a Match at line number. I need to run three or four names at a time through this script to see if they are already there. But it does not seam to work. And I can not figure out way. A small sample of the file is below. $fd = fopen ("virtusertable", "r"); $line_text= "[EMAIL PROTECTED]"; $count = 1; while ($line_text = fgets($fd, 2048)) { if ($variable = trim($line_text)) { echo "Match at line number $count"; break; } ++$count; } [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] Best regards, Richard mailto:[EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]