Results 1 to 4 of 4
  1. #1
    Join Date
    Jul 2004
    Posts
    30

    Unanswered: can i read array contents from file?

    i'm doing something like the following
    Code:
    $dictionary=array(
    1=>"word1",
    2=>"word2",
    3=>"word3",
    4=>"word4",
    5=>"word5",
    6=>"word6");
    I might change the contents anytime, inserting a word between 1 & 2, or moving word3 to be displayed after word5 etc..

    it's very troublesome to change a code everytime,
    so is there anyway that i can read from a conf file, and insert everyline from conf file to the array?

    i only have to write:
    word1
    word2
    word3
    word4
    word5
    word6
    in my conf file, and it will be inserted into my array according to the sequences in the conf file.

    thanks

  2. #2
    Join Date
    Jan 2004
    Location
    India
    Posts
    168
    You question is not that clear..but still based ona guess like
    if you want to insert some values into an array based ona sequesnce from a conf file you have to check the order in the conf file first and the use array_push() function to insert the value.

    Regards
    Rajesh
    Freelance and Technology Consultant
    -------------------
    Dreams are for ever
    -------------------

  3. #3
    Join Date
    Feb 2004
    Posts
    533
    I don't have a ready example to show you, but what you'll need to do is read in the file, Use the Explode Function to convert the text to an array.
    $array = explode("\n", $string); arguments are 'delimiter' and 'string to explode'
    use array_push to add variables to the array.
    use the implode function to rejoin the array.
    write the array back to the file.

    This may help
    Unset Function
    http://www.php.net/manual/en/function.unset.php

    Array Functions
    http://www.php.net/manual/en/ref.array.php

    '
    Last edited by savbill; 10-05-04 at 13:01.
    ~

    Bill

  4. #4
    Join Date
    Jul 2004
    Posts
    30
    thanks rajest & savbill,

    i've found out another way to do it, that's with eval()
    experimenting everything now

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •