duankeye2342 2014-01-14 17:46
浏览 23
已采纳

返回所有文本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.

  • 写回答

3条回答 默认 最新

  • doujiang1832 2014-01-14 17:59
    关注

    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;
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 有偿 写代码 要用特定的软件anaconda 里的jvpyter 用python3写
  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题