我正在读取一种'类'csv文件并将其分解并将其存储在数组中。在PHP中使用file_get_contents读取一个CSV
的文件我读了这个结构
Id,Log,Res,File
mydb('Test1','log1','Pass','lo1.txt').
mydb('Test2','log2','Pass','lo2.txt').
mydb('Test3','log3','Pass','lo3.txt').
现在我所要做的是: 读我的数据库中的最后一条记录,得到了名字,让我们在这种情况下说“测试1”和然后我通过我的文件进行搜索,在那里我可以找到'Test1'的位置并获取文件中的下一行,提取ID,并将其添加到数据库。
我正在获取文件中所需字符串的位置,但我不知道如何获取下一行。
这是我的代码到目前为止。
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("testing") or die(mysql_error());
$result = mysql_query("select ID from table_1 order by S_no DESC limit 1") or die(mysql_error());
$row = mysql_fetch_array($result);
$a = $row['ID'];
echo 'Present Top Row is '.$a.'<br>';
$addresses = explode("\n", file_get_contents('\\\\fil1\\logs\\tes.pl'));
foreach($addresses as $val)
{
$pos = strstr($val, $a);
if ($pos === false) {
} else {
echo "The string <br> '$a' <br>was found in the string <br>'$val' <br>";
echo " and exists at position <br>$pos<br>";
}
}