Если вы не хотите получать файл, как показано в pavanlimo, другой вариант - извлечь переменные с помощью цикла:
while read propline ; do
# ignore comment lines
echo "$propline" | grep "^#" >/dev/null 2>&1 && continue
# if not empty, set the property using declare
[ ! -z "$propline" ] && declare $propline
done < /path/to/config/file
В PHP применяются те же основные понятия:
// it's been a long time, but this is probably close to what you need
function isDeclaration($line) {
return $line[0] != '#' && strpos($line, "=");
}
$filename = "/path/to/config/file";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
$lines = explode("\n", $contents); // assuming unix style
// since we're only interested in declarations, filter accordingly.
$decls = array_filter($lines, "isDeclaration");
// Now you can iterator over $decls exploding on "=" to see param/value
fclose($handle);