-1

我在下面有这段代码用于更新文本文件中的一行。

$filename = "flat-file-data.txt"; // File which holds all data
$rowToUpdate = 1; // This is line need to be updated
$newString = "This text is updated\n"; // This is what you want to replace it with

$arrFp = file( $filename ); // Open the data file as an array
// Replace the current element in array which needs to be updated with new string
$arrFp[$rowToUpdate-1] = $newString; 
$numLines = count( $arrFp ); // Count the elements in the array

$fp = fopen( $filename, "w" ); // Open the file for writing
for($i=0; $i<$numLines; $i++) // Overwrite the existing content
{
    fwrite($fp, $arrFp[$i]);
}
fclose( $fp ); // Close the file

但不幸的是,我在第 108 行的 D:\PROGRAM FILES\wamp\www\mindandsoul\processor.php 中收到一条错误消息:“解析错误:语法错误,意外 ';',期待 ')'”。是什么意思?我怎样才能摆脱它?有什么办法可以解决这个错误?

4

1 回答 1

2

问题是这一行:

for($i=0; $i<$numLines; $i++)

&lt;必须替换为<

像这样:

for($i=0; $i < $numLines; $i++)
于 2013-07-27T19:33:08.257 回答