how can I have the array read file?

Discussion in 'PHP' started by greenworld, Aug 2, 2006.

  1. #1
    hi;
    how can make array read text file insead of having some value in it,

    example:
      
    $alldata = array(" this is text 1", "this is text 2", "this is text 3", "ththis is text 4" , "this is text 5", "this is text 6", "this is text 7");
    
    PHP:
    now I want to put all the above values in a text file, which is much easier to work with. then seperate the value with a delimiter may be the same comma would do it bu i will hav problem because the text has comma in it which will mess with the actual value,

    if I use a read file script like this:

    
    $filename="data.txt"; 
    $alldata = array(); 
    $file = fopen($filename, "r"); 
    while(!feof($file)) { 
    
        $alldata[] = fgets($file, 4096); 
       
    } 
    fclose ($file); 
    print_r($alldata); 
    ?>
    
    PHP:
    how can I make it work together with the array?

    thanks
     
    greenworld, Aug 2, 2006 IP
  2. clancey

    clancey Peon

    Messages:
    1,099
    Likes Received:
    63
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this:

    
    $alldata = file("data.txt");
    print_r($alldata);
    
    Code (markup):
     
    clancey, Aug 2, 2006 IP