Jump to content

PLEASE HELP AM NEW TO PHP


ibnmuhammad

Recommended Posts

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

 

BUT IT SHOULD PRINT ALL THE INFORMATION IN THE TXT FILE ONE AFTER THE FILE UNDER EACH

 

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

 

PLEAAASEEE HELPPPPPPP ME WITH MY PROBLEM AM VERY NEW TO PROGRAMMING

 

 

php:

 


<? 

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

Link to comment
Share on other sites

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

)

 

Link to comment
Share on other sites

try

<? 

$filename = "filename.txt"; 
$filepointer = fopen($filename, "r"); 
$myarray = file ($filename); 


for ($mycount = 0; $mycount < count ($myarray);$mycount++) 
{ 

        $aline = $myarray[$mycount]; 
        $cd = str_replace(',',"<br />\n", $aline);
        //$cd = getvalue($myarray[0], $mycount); 

        print "$cd" . "<br> \n"; 

} 

function getvalue($file, $mycount) 
{ 
        
        $intoarray = explode (",", $file); 
        return $intoarray[$mycount]; 

} 
fclose($filepointer); 
?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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