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

  • SEARCH
  • Home
  • 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 8193561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:31:04+00:00 2026-06-07T04:31:04+00:00

I have a PHP file which writes some information into a configuration file which

  • 0

I have a PHP file which writes some information into a configuration file which looks a bit like this…

#Date=01/2012
text1=hello
text2=goodbye

etc…

This file is written as a cfg file to be used by a perl script, but I need the file to be read back into PHP so it can be edited each time for the perl script to use again.

How can this be done?

I previously had it write into a .csv file and be read back in, but then was told this was not what was needed and it had to be in a cfg file, so will it be just as easy to add the info back into the PHP script as it is when reading in a .csv file.

I think what is needed is to not have the text1 and text2 variables to be read in, but to have what is after the equals to be read back in so the hello and goodbye strings would be read back into the PHP.

Another thing is that when the user adds in more info to say text1 it will have more than one value e.g. they could change text1 to…

text1=hello,howareyou

Then that , would need to be a seperate entity within the PHP script so I’m guessing I would use the explode function to get the seperate pieces of data.

This data will be read into a table where the user can then edit the information ready for when the perl script gets run again.

My HTML would be something like this when the info is read in.

<table>
    <tr>
        <td>text 1</td>
        <td>hello</td>
        <td>howareyou</td>
    </tr>
    <tr>
        <td>text 2</td>
        <td>goodbye</td>
    </tr>
</table>

I hope I have made myself clear with this and I am really struggling to comprehend how this could be done. As it doesn’t seem as easy as reading from a .csv

Also I don’t want the PHP to execute the script, I just need it to be read into the PHP so the user can edit the information again.

  • 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-07T04:31:06+00:00Added an answer on June 7, 2026 at 4:31 am

    Try this. You end up with a tidy associative array – param names as element names, and param values as element values.

    $cfg_path = 'path/to/config.cfg';
    if (file_exist($cfg_path)) {
        if (preg_match_all('/^(?!#)(.+)=(.*)$/m', file_get_contents($cfg_path), $cfg)) {
            $cfg = array_combine($cfg[1], $cfg[2]);
            foreach($cfg as $name => $val)
                echo $name.' = '.$val.'<br />';
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a php file which has some variables like $name1, $name2... How can
I have a PHP file which will return something like <div id=title>Add Us On
I have a php file which has a require_once Statement (?) this file is
i have a php file which stores a variable, and i need to create
I have a php file which checks for login and password from users database,
I have a PHP file which my clients will execute on their server. It
i have one php file which process adding of record in Database fro array.
I have a small php file which just creates the tables in a database.
I have a index.php file which loads (require) 2 different files based on a
I have an index.php file which has 2 included files require(stats.php); require(stats_encry.php); stats.php which

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.