解析文本文件更新行中的错误108

时间:2013-07-27 19:30:40

标签: php

我在下面有以下代码来更新文本文件中的一行。

$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中收到错误说“解析错误:语法错误,意外错误';',期待')'”。假设它意味着什么?我怎么能摆脱它?任何方法来解决错误?

1 个答案:

答案 0 :(得分:2)

问题在于这一行:

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

&lt;必须替换为<

像这样:

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