Forum Moderators: coopster
keyword1
keyword2
keyword3
keyword4
etc...
and have them automatically put into variables
$key1 = keyword1
$key2 = keyword1
$key3 = keyword1
$key4 = keyword1
etc...
I've been racking my brain trying everything and I can't get any results... nyone know an easy way?
<?
$sfp = fopen('/path/to/file.txt','r');
$counter = 1;
while ($line = fgets($sfp)) {
${'key' . $counter} = $line;
$counter++;
}
fclose($sfp);
?>
you now have as many variables as there are lines in the file. Each variable is in the format you mentioned $key1, $key2 etc.
they will have line endings in the strings so you may want to replace \n or \r or both in the var $line when you assign to $keyX
but that will work