PHP code read and writes to file fine UNTIL i compare a substring -


the following php code works read 1 file , write same content file:

<?php  $input = @fopen("./temp.def", "r"); $output = @fopen("./temp.tpc","w");  if ($input) {      while (!feof($input)) {         $buffer = fgets($input);         fputs($output, $buffer);     }     if (!feof($input)) {         echo "error: unexpected fgets() fail\n";     }      fclose($input);     fclose($output);  } 

but when add code replace content based off of whether or not substring specific text doesn’t work. here’s code that:

<?php  $input = @fopen("./temp.def", "r"); $output = @fopen("./temp.tpc","w");  if ($input) {      while (!feof($input)) {         $buffer = fgets($input);          //check see if `row`  line         $isrow = mb_substr($buffer, 0, 5, 'utf-8');         if ($isrow == "row=:") {             $data = str_ireplace("row=:", "base=:[loc^nb]" . chr(10) . "row=:", $buffer);             else {                 $data =  $buffer;             }         }          fputs($output, $data);     }     if (!feof($input)) {         echo "error: unexpected fgets() fail\n";     }      fclose($input);     fclose($output);  } 

the thing changed in code added part, highlighted in yellow, , variable name change, highlighted in blue...

color-highlighted code

you have weird bracing going on there. try:

if ($isrow == "row=:") {     $data = str_ireplace("row=:", "base=:[loc^nb]" . chr(10) . "row=:", $buffer); } else {     $data =  $buffer; } 

Comments