Jump to content

Recommended Posts

Hey forums; So basically I have a PHP file (checkIP.php) that checks the IPs posted through another script against a list of IPs in a text file; I can read a text file line-by-line just fine, using "fgets()" and handles, but when I try to add the variables to an array list, it only adds the last IP to the arraylist.

 

I'm using this code to set the array list.

 

$ipList = array($buffer);

 

the script i'm using to get the text line-by-line is:

$handle = @fopen("./IPs.txt", "r");
if ($handle) {
    while (($buffer = fgets($handle, 4096)) !== false) {
        echo $buffer;
    }
    if (!feof($handle)) {
        echo "Error: unexpected fgets() fail\n";
    }
    fclose($handle);
}

 

I'm sorry if this is a newbie question.

Link to comment
https://forums.phpfreaks.com/topic/241939-problem-with-an-array/
Share on other sites

not sure how you are inputing the lines from fgets into the array since its not actually in your code...but here

 

$handle = @fopen("./IPs.txt", "r");
if ($handle) {
    while (($buffer = fgets($handle, 4096)) !== false) {
        echo $buffer;
        $ipList[] = $buffer
    }
    if (!feof($handle)) {
        echo "Error: unexpected fgets() fail\n";
    }
    fclose($handle);
}
print_r($ipList);

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.   Restore formatting

  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.

×
×
  • 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.