【发布时间】:2014-02-24 10:50:31
【问题描述】:
我有一个文本文件 write.txt:-write.txt
My name
jai hind
stack
我在以下代码的第 154 行和第 165 行收到错误,错误是:-
PHP 注意:未初始化的字符串偏移量:/home/sakshi/Desktop/syllabify/step2/Syll_script_1.php 第 154 行中的 11
PHP 注意:未定义的偏移量:/home/sakshi/Desktop/syllabify/step2/Syll_script_1.php 第 165 行中的 -2
代码:-
$file1 = fopen("write.txt", "r");
$q=1;
while ( $line = fgets($file1) )
{
$i=0;
$arr = explode( "\n", $line );
$q=$q+1;
if(strcmp($arr[0],"." ) == 0)
{
$i=1;
$q=$q-1;
echo "\nposition of dot in write.txt:";
echo "$i \t $q\n";
break;
}
}
fclose($file1);
if($i==0)
echo $i;
while ( $q!=1 )
{
$file_input=fopen("input.txt","r");
$line = fgets($file_input);
$p = strlen($line);
echo $p;
$a=2;
if ($p == $a)
{
$m = $line[0];
echo "$m\n";
$l=0; $h=0;
$filename=fopen("write.txt","r");
$content=file("write.txt");
for($i=0;$i<$u-1;$i++)
{
$arr=$content[$i];
$length=strlen($arr);
for($j=0;$j<=$length;$j++)
{
if(strcmp($arr[$j],$m ) == 0)// line 154
{
echo "\nYES PRESENT AT LINE NUMBER: ";
$h=$i+1;
echo "$h\n";
$l=$h+1;
}
}
break;
}
/********************************************************/
$arr3=$content[$l-2];// line 165
$ar3=explode(" ",$arr3);
$output_file=fopen("Result.txt","a");
fwrite($output_file,$ar3[0]);
fwrite($output_file," ");
fclose($output_file);
$output_file=fopen("Result.txt","a");
fwrite($output_file,$ar3[1]);
fwrite($output_file," ");
fclose($output_file);
$ar3=str_replace("\n","",$ar3);
$output_file=fopen("Result.txt","a");
fwrite($output_file,$ar3[2]);
fclose($output_file);
/************************************************************/
// put enter at the end of operation
$output_file=fopen("Result.txt","a");
fwrite($output_file,"\n");
fclose($output_file);
/**********************************************************/
}
【问题讨论】:
-
你能发布你的完整代码吗?
-
我复制了代码,加了两个'}',没有报错。
-
什么是
$u?这不是完整的代码。 -
你初始化$m了吗?
-
你想要什么准确的输出,这样我们会更好地理解..