Hey every one,
I got this problem with my code and would love it if any one could help with this probelm.
Am creating a program that reconises commas in text file (comma delimited code) and i want to implement the same function and loop. This
program should get the file, store it ina array then enter a loop that jumps in to the
function.
here is the txt file:
Take That, Greatest Hits, 2007, 10.99, 35
50cent, Am Back, 2005, 11.88, 70
Mike Jone, Never Sing Alone, 2007, 12.99, 30
Terry Gamble, Alone, 1987, 13.99, 40
Michael Jackson, Am Bad, 1990, 15.99, 60
The problem is the code below displays this:
Take That
Am Back
2007
13.99
60
It should print all the information in the text file, one after the the other; like this:
Take That
Greatest Hits
2007
10.99
35
50cent
Am Back
2005
11.88
70
Mike Jone
Never Sing Alone
2007
12.99
30
Terry Gamble
Alone
1987
13.99
40
Michael Jackson
Am Bad
1990
15.99
60
Please help me with my problem. I am very new to programming.
<?
$filename = "filename.txt";
$filepointer = fopen($filename, "r");
$myarray = file ($filename);
for ($mycount = 0; $mycount < count ($myarray);$mycount++)
{
$aline = $myarray[$mycount];
$cd = getvalue($myarray[0], $mycount);
print "$cd" . "<br> \n";
}
function getvalue($file, $mycount)
{
$intoarray = explode (",", $file);
return $intoarray[$mycount];
}
fclose($filepointer);
?>
The array has this content from a txt file:
Array
(
[0] => Take That, Greatest Hits, 2007, 10.99, 35
[1] => 50cent, Am Back, 2005, 11.88, 70
[2] => Mike Jone, Never Sing Alone, 2007, 12.99, 30
[3] => Terry Gamble, Alone, 1987, 13.99, 40
[4] => Michael Jackson, Am Bad, 1990, 15.99, 60
)
[ Mod Edit - bpat1434 ] Please use netiquette when posting. There is NO need to shout (use all caps) your subject or any lines in your posts. We have vBCode here for stylization and the creation of emphasis. I have removed your shouting and replaced it with nicer text (kept the same meaning, cleaned up the english a little bit too.)