2016-10-20 26 views
0
<?php 

$flag =''; 
$searchthis = $_GET["searchthis"]; 
$items = array('Release:', 'Kernel:', 'Network:', 'CPU:', 'Memory:', 'Disk:', 'Packages:'); 
$hostname = $_GET["hostname"]; 
$file = new SplFileObject($hostname."_inventory.txt"); 
$i=1; 
echo $file; 
$lines = file($file); 

這裏的預期目標是將文件對象$ file的每一行讀入一個數組,以便我可以循環訪問它。當我運行上面的代碼時,結果始終是項目數組中的第一個字符串,一遍又一遍,即。版本:Release:發佈:Release:等。新的SPLFileObject變量設置錯誤?

回答

0

使用file數組正確。

$flag =''; 
$searchthis = $_GET["searchthis"]; 
$items = array('Release:', 'Kernel:', 'Network:', 'CPU:', 'Memory:', 'Disk:', 'Packages:'); 
$hostname = $_GET["hostname"]; 
$file = new SplFileObject($hostname."_inventory.txt"); 
foreach($file as $fl){ 
    echo $fl.'PHP_EOL'; 
} 
+0

這就是我正在尋找的。謝謝 – user3538059