从文件中读取并使用explode功能

时间:2014-10-19 15:57:14

标签: php explode trim file-handling filehandler

我需要帮助。 我有一个包含数字的文件:

105 5001 5450 1548

5158 7875 8785 2404

5410 1548 0 0

现在应该从这个文件中读取然后保存一行的数字(除了数字之间有空格),并保存在Variable上。 例如:第一行:

$o = 105    $s=5001    $j=5450    $m=1548 

1 个答案:

答案 0 :(得分:0)

我希望我的问题是正确的。这可能会有所帮助

<?php
$handle = fopen("inputfile.txt", "r");
if ($handle) {
    while (($line = fgets($handle)) !== false) {
        list($o, $s, $j, $m) = explode(' ', $line);
        // do soethings with your variables $o, $s, $j, $m
    }
} else {
    // error opening the file.
}
fclose($handle);
相关问题