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]