Jump to content

Problem with an Array


n00bl3z

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);

Archived

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

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