I'm trying to pull ip addresses from a text file and put them into a mysql database. When ever it inserts entries though it comes up as the word array. And I don't understand why. If anyone could shine some light on this I would appreciate it. Thanks!
<?
$fd = fopen ("iptest.txt", "r", 100);
$x = 0;
$z = 0;
global $var;
while (!feof ($fd)) {
$buffer = fgets($fd, 4096);
$frog = $buffer;
preg_match_all("/([0-9]+.[0-9]+.[0-9]+.[0-9]+)/", $frog, $matches);
for ($i=0; $i< count($matches[0]); $i++) {
$x= "$x" + "1";
echo "Address ".$x.": ".$matches[1][$i]."\n <BR>";
$var[$z] [0]= $matches[1][$i];
$z= "$z" + "1";
}
}
fclose ($fd);
for ($i=0; $i< count($var); $i++) {
echo "Here it is: ".$var[$i][0]."\n <BR>";
if($var) {
$query = "INSERT INTO IP ";
$query .= "(ip)";
$query .= "values ('$var[0]')";
mysql_connect("localhost","shroder","haze")
or die("Failure to connect to sql server");
mysql_select_db("ip") or die("Unable to select database");
mysql_query($query) or die ("Insert Failed!");
}
else
{
}
}
?>