返回所有文本PHP

Im reading a file on php using this code

    $file_array = parse_ini_file("/usr/local/etc/oscam.user");
    echo "<pre>";
    foreach ($file_array as $value) {
        echo $value."<br />";
    }
    exit;

That will output

sovrum
pass2
1
0
0B00
0B00:000000

Thats correct but the problem is, its just returning the end of my file ( the last element ) my file looks like this

[account]
user                          = vrum
pwd                           = pass1
group                         = 1
au                            = 1
caid                          = 0B00
ident                         = 0B00:000000

[account]
user                          = sovrum
pwd                           = pass2
group                         = 1
au                            = 0
caid                          = 0B00
ident                         = 0B00:000000

As you can see theres more accounts to read.

As you cannot change the original file, probably you will have to parse it by hand, with something like this:

$handle = @fopen("oscam.user", "r");
if ($handle) {
    while (($line = fgets($handle)) !== false) {
        if(strlen(trim($line)) > 0 && $line[0] != "[") {
            $ar = explode("=", $line);
            echo(trim($ar[1]));
        }
    }
}

Original Answer:

parse_ini_file will overwrite the values, as they have the same name. You probably want to have your text file like:

[account]
user[]                          = vrum
pwd[]                           = pass1
group[]                         = 1
au[]                            = 1
caid[]                          = 0B00
ident[]                         = 0B00:000000

[account]
user[]                          = sovrum
pwd[]                           = pass2
group[]                         = 1
au[]                            = 0
caid[]                          = 0B00
ident[]                         = 0B00:000000

and, in order to get all the values:

$file_array = parse_ini_file("/usr/local/etc/oscam.user");
echo "<pre>";
foreach ($file_array as $val_array) {
    foreach($val_array as $value) {
        echo $value."<br />";
    }
}
exit;

I'm assuming pass1 and pass2 are replacements for actual passwords, in which case a character in there could throw off the parse. Try to use INI_SCANNER_RAW as the $scanner_mode. This will keep php from trying to parse the values.

Edit: using your values and the equivalent parse_ini_string() function, this seems to work fine: https://eval.in/89029

$content = file_get_contents("/usr/local/etc/oscam.user");
preg_match_all('/\]([^\[]+)/s', $content, $matches);

echo "<pre>";
foreach ($matches[1] as $block) {
    $array = parse_ini_string($block);
    foreach ($array as $value) {
        echo $value."<br />";
    }
}
echo "</pre>";
exit;

Parsing file to blocks, separating by symbols from "]" to "[", then parsing ini_string of each block and then printing them values.