Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7759951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:45:22+00:00 2026-06-01T13:45:22+00:00

I am having trouble figuring out how to write to a file using fopen

  • 0

I am having trouble figuring out how to write to a file using fopen “a” append mode.

the file itself is a simple PHP array:

$array = array(
  "entry1"   => "blah blah",
  "entry2"   => "forbarbaz",
);   

simple enough. So using fopen with the 2nd arg set to “a” should allow me to append the file using fputs…. the problem is the opening and closing lines, ie $array = array( and );

so now the file should look like this:

  "entry1"   => "blah blah",
  "entry2"   => "forbarbaz",

how would I rebuild this data into a working PHP array assuming it is just a txt file with a list of entries without the opening and closing lines? Sorry if this is not clear, its a little complicated. No I am not going to store these values in a DB, I need the speed advantage by holding these particular values in a file array.

So the questions really is how would i go about constructing the usable PHP array from a txt file with a line by line list like this?

To clarify:

how do i pull in a txt file with lines like this:

  "entry1"   => "blah blah",
  "entry2"   => "forbarbaz",

and have a workable $php_array()????

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T13:45:23+00:00Added an answer on June 1, 2026 at 1:45 pm

    Try this.

    File format (at the beginning of work with it):

    <?php
    $array = array();
    

    Now it’s correct php-file.

    Then simply add new rows like as follows:

    $f = fopen('myarray.php', 'a');
    fputs($f, PHP_EOL.'$array["entry1"] = "value1";');
    fclose($f);
    

    And use it by simply include('myarray.php');

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i'm having some trouble figuring out how to save unicode into a file in
I'm having trouble figuring out what my Flex Project is expecting from my PHP
im having trouble figuring out how to bind mouseout() to my entire nav bar
I'm having trouble figuring out how to delete a set of records when a
I'm having trouble figuring out a way to conditionally cancel an asp:TextBox's OnTextChanged AutoPostBack
I'm having trouble figuring out how to create a foreign key constraint. My data
I'm having trouble figuring out how to exclude /public/bin from this rewrite rule RewriteCond
I'm having trouble figuring out how to represent the following JPQL query: SELECT count(e)
I am having trouble figuring out how to 're-render' a page after a POST
I'm having trouble figuring out how to correctly merge rows. Looking at the sample

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.