$file = file("names.txt"); $search = "sdgdgdfg dgdfgdf"; $i = 0; $k = ''; foreach($file as $v){ if($v == $search) { $k = $i++; $j = $k + 5;//количество строк после искомого слова } $i++; } while($k < $j) { echo $str_new[$k]; $put .= "<a href='/$str_new[$k]'>$str_new[$k]</a>\n"; $k++; } file_put_contents($put, $search); 

I do not understand where the error (((names.txt

 sdf sdfsd test sdfsdf sgdf sdgdgdfg dgdfgdf test fgd testdfg dgdfgdf dgdfgdf 

Help solve

  • What kind of mistake? - Andrey Shpileva
  • The fact of the matter is that an empty file is created ... - allanklinton
  • Notice: Undefined variable: j in /var/www/d.php on line 13 Notice: Undefined variable: put in /var/www/d.php on line 19 - allanklinton

1 answer 1

how to find the error:

  1. Enable error output
  2. go to https://translate.google.com/ and insert the text of the error, look at the translation.
  3. Aha $ j not defined
  4. do var_dump before if var_dump($v == $search,$v,$search)
  5. aha does not work why?
  6. Yes, because a pancake in $v has spaces, newlines, and so on.
  7. Trim before comparison if(trim($v) == trim($search))
  8. everything is working!