PHP - display from txt file with explode function

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • 848lu
    New Member
    • Dec 2006
    • 37

    #1

    PHP - display from txt file with explode function

    PHP - display from txt file with explode function

    hi, i am trying to display all data from a txt file with a function of explode but does not work.....

    [PHP] <?
    #reads a text file outputs it to screen
    $filename = "cdlist.txt ";
    $filepointer = fopen($filename ,"r"); // open for read
    $cdArray = file ($filename);

    for ($mycount = 0; $mycount < count($cdArray) ; $mycount++ )
    {
    $string = getvalue ($cdArray,1);
    $aline = $cdArray [$mycount];
    print "$aline $string \n";
    }
    fclose ($filepointer);

    function getvalue ($text, $commaToLookFor )
    {
    $intoarray = explode(",",$te xt);
    return $intoarray[ $commaToLookFor];
    }

    if (!($filepointer = fopen($filename ,"r"))) { exit; }
    ?>

    [/PHP]
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, 848lu.

    Are you looking for fgetcsv()?

    Comment

    Working...