php编程中的错误
我有一个文本文件write.txt:-write.txtphp编程中的错误,php,string,file,Php,String,File,我有一个文本文件write.txt:-write.txt My name jai hind stack 我在以下代码的第154行和第165行得到错误,错误是:- PHP注意:未初始化的字符串偏移量:第154行的/home/sakshi/Desktop/syllaify/step2/Syll_script_1.PHP中的11 PHP注意:未定义的偏移量:-2 in/home/sakshi/Desktop/syllaify/step2/Syll_script_1.PHP,第165行 代码:-
My name
jai hind
stack
我在以下代码的第154行和第165行得到错误,错误是:-
PHP注意:未初始化的字符串偏移量:第154行的/home/sakshi/Desktop/syllaify/step2/Syll_script_1.PHP中的11
PHP注意:未定义的偏移量:-2 in/home/sakshi/Desktop/syllaify/step2/Syll_script_1.PHP,第165行
代码:-
$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);
/**********************************************************/
}
$file1=fopen(“write.txt”、“r”);
$q=1;
而($line=fgets($file1))
{
$i=0;
$arr=分解(“\n”,$line);
$q=$q+1;
如果(strcmp($arr[0],“)==0)
{
$i=1;
$q=$q-1;
echo“\n write.txt中点的位置:”;
回显“$i\t$q\n”;
打破
}
}
fclose(1美元);
如果($i==0)
echo$i;
而($q!=1)
{
$file_input=fopen(“input.txt”、“r”);
$line=fgets($file\u输入);
$p=strlen($line);
echo$p;
$a=2;
如果($p=$a)
{
$m=$line[0];
回显“$m\n”;
$l=0;$h=0;
$filename=fopen(“write.txt”、“r”);
$content=文件(“write.txt”);
对于($i=0;$i而言,问题出现在以下行中:
for($j = 0; $j <= $length; $j++)
for($j=0;$j在访问元素之前检查$arr是否是数组。您能发布完整的代码吗?我复制了代码,添加了两个'}'并且没有出现错误。$u
?这不是完整的代码。您初始化了$m吗?您想要的是准确的输出,以便我们更好地理解。$arr是一个已分配字符串的变量。但我正在尝试从$arral访问每个字符,以检查它是否为空
for($j = 0; $j < $length; $j++)
$j < strlen();
$j <= strlen() - 1;