Re: [PHP] Re: How to read PHP variables.

2005-07-15 Thread Bruno B B Magalhães

Hi everybody,

well I don´t want to include and use those variables or  set then. I  
want to read the file, parse the vars to a form, so the user can  
change the system configs using the web instead of FTP...


I am thinking reading using a simple include, and then clean the file  
contents and write the strings..


Best Regards,
Bruno B B Magalhães

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: How to read PHP variables.

2005-07-15 Thread Edward Vermillion

Bruno B B Magalhães wrote:

Hi everybody,

well I don´t want to include and use those variables or  set then. I  
want to read the file, parse the vars to a form, so the user can  change 
the system configs using the web instead of FTP...


I am thinking reading using a simple include, and then clean the file  
contents and write the strings..


Best Regards,
Bruno B B Magalhães

One simple way that I've done that in the past is to have a file, which 
is a basic php file like:


?php

$INFO['prefix_sectionInForm'] = 'whatever';

?


Include that file then do

foreach( $INFO as $in_key = $in_val )
{
if( preg_match(/prefix_/, $in_key) )
{
$db_info[$in_key] = $in_val;
}
}
foreach( $db_info as $in_key = $in_val )
{
$text = ucfirst(substr( $in_key, however long the prefix is ));
$print Some descroptor based on the prefix.$text
input type='text' name='$in_key' value='in_val' /
}

Then just write it all back out on the form processor part, with some 
security checking of course:


$file_string = ?php\n;

$update is an array with the key values I want..

foreach( $update as $info_key )
{
foreach( $input as $in_key = $in_val )
{
if( $info_key == $in_key )
{
$new[$info_key] = $in_val;
}
}
}

foreach( $new as $k = $v )
{
$file_string .= \$INFO[.'.$k.'.]\t\t\t=\t\.$v.\;\n;
}

$file_string .= \n.'?'.'';

Write $file_string back out to the config file.

Like I said, there's more to the script than this, error checks, seurity 
checks and the like, but this is the 'meat' of it all.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: How to read PHP variables.

2005-07-15 Thread André Medeiros
What about...

form action=saveConfig.php method=post

Database Host: input type=text name=config[database][host]
value=?=$config['database']['host']? /br /
Database User: input type=text name=config[database][user]
value=?=$config['database']['user']? /br /

!-- some more fields here --

/form

And then...

?php
$newConfigValues = $_POST['config'];

$fileCode = ?php\n// AUTOMATICLLY CREATED CONFIG FILE. DO NOT EDIT!
\n;
foreach( $newConfigValues as $parentConfigKey = $parentConfigValue ) {
if( is_array( $parentConfigValue ) {
foreach( $parentConfigValue as $childConfigKey = 
$childConfigValue )
{

$fileCode .= 
$config['$parentConfigKey']['$childConfigKey'] =
'$childConfigValue';\n;

}
}
else {
$fileCode .= $config['$parentConfigKey'] = 
'$parentConfigValue'\n;
}
}

$fileCode .= ?;

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php