如何在用户发送值时创建PHP配置文件?

I want to know if there is anyway that php can write a config file after a user send a form (like how wordpress setup)

Since I want to make my php project setup file, so I need to write an ini file (or php), But I don't know how exactly how to.

So How am I suppose to do? because telling the user to edit the php file is too odd, as they probably won't know how to.

I have tried creating an "ini" file, but it only can read, I don't know how to write it.

here is a class to work with (how ever regex is not a good idea to work with!)

class ConfigFileManager
{
    private $configFile = null;
    private $items = array();
    function __construct($file_address)
    {
        if(file_exists($file_address))
        {
            $this->configFile = $file_address;
            $this->parse();
        }
    }
    function __get($id) { return $this->items[ $id ]; }
    function __set($id,$v) { $this->items[ $id ] = $v; }
    function parse()
    {
        if($this->configFile != null)
        {
            $fh = fopen( $this->configFile, 'r' );
            while( $l = fgets( $fh ) )
            {
             if ( preg_match( '/^#/', $l ) == false )
             {
                preg_match( '/^(.*?)=(.*?)$/', $l, $found );
                if($found)
                $this->items[ trim($found[1]) ] = trim($found[2]);
             }
            }
            fclose( $fh );
        }
        else
        {
          $this->file_not_exist();
        }
    }
    function save()
    {
        if($this->configFile != null)
        {
            $nf = '';
            $fh = fopen( $this->configFile, 'r' );
            while( $l = fgets( $fh ) )
            {
                if ( preg_match( '/^#/', $l ) == false )
                {
                    preg_match( '/^(.*?)=(.*?)$/', $l, $found );
                    $nf .= $found[1]."=".$this->items[$found[1]]."
";
                }
                else
                {
                    $nf .= $l;
                }
            }
            fclose( $fh );
            copy( $this->configFile, $this->configFile.'.bak' );  //backup last configs
            $fh = fopen( $this->configFile, 'w' );
            fwrite( $fh, $nf );
            fclose( $fh );
        }
        else
        {
            $this->file_not_exist();
        }
    }
    private function file_not_exist()
    {
       //throw exception that you want
        echo "File Does Not Exist";
    }
}

example of how to work with this class

    $config = new ConfigFileManager('configs/config.ini');  //opening file config.ini from configs directory  

    echo $config->Title;  //read  "Title" value which is equal to  "My App"  

    $config->Title = "Your App";  //changing value of "Title"  

    $config->save();  //save changes to config.ini easily