我需要从 PHP 中的“libconfig”格式文件中读取和写入变量。但是我在任何地方都找不到图书馆。我当然知道 C/C++ 库,但我们必须编写一个扩展来使用它。
这样的库或扩展是否存在?
function parseLibconfig_section( &$Array, &$LineID ){
$RetVal = array(); // Initializing return value as empty array
while( count( $Array ) > $LineID ){ // While not riches last line
if( stripos( $Array[$LineID] , ':' ) !== false ){
// In case we have section Title - just remember it
// The section will parsed later at section begin (next loop)
$TArr = explode( ' ', trim( $Array[$LineID] ) );
$CS = $TArr[0];
} elseif( stripos( $Array[$LineID] , '{' ) !== false ){
// We at section open Tag -> call recurrent function to parse
// from next line of input data
$LineID++;
$RetVal[$CS] = parseLibconfig_section( $Array, $LineID );
} elseif( stripos( $Array[$LineID] , '}' ) !== false ){
// End of section - return back from subsection
break;
} else {
// nor section begin/ nor section end - parse line as field
// by standard PHP function parse_ini_string (please see PHP ref)
$TVrr = parse_ini_string( trim( $Array[$LineID] ) );
if( count( $TVrr ) ){
// fill return array by fields from parse_ini_string function
foreach( $TVrr as $Key => $Val ) $RetVal[$Key] = $Val;
};
};
// Next please!
$LineID++;
};
return $RetVal;
};
function parseLibconfig( $FName ){
$RetVal = array(); // Initializing return value as empty array
$Data = file( $FName ); // Reading content of libconfig's
// config file into array of lines
if( count($Data)> 0 ){ // If we have some data read then - working
$Index = 0; // Init an variable to pass by reference into
// function that will be called recursively
$RetVal = parseLibconfig_section( $Data, $Index );
};
return $RetVal;
};