i have a text file def.txt which looks like :-
Type total used free shared buffers cached
Mem: 4039 762 3277 0 59 251
i want to read the file word wise and insert these in mysql database as above format. please help me sort this out.
my current code is :-
$fh = fopen('F:\images\def.txt','r') or die($php_errormsg);
for($i=0;$i<=1;$i++)
{
if ($s = fgets($fh,1048576))
{
$words = preg_split('/\s+/',$s,-1,PREG_SPLIT_NO_EMPTY);
$imp = implode(" ",$words);
$con = mysqli_connect("localhost","root","root","test") or die("no connection".mysqli_connect_error());
$a = "insert into test1 values('$imp')";
if(mysqli_query($con,$a))
{
echo "done"."<br>";
}
else
{
echo "not done".mysqli_error($con)."<br>";
}
mysqli_close($con);
}
echo "<br>";
}
fclose($fh) or die($php_errormsg);