I have file to edit that contains:
Categories,
Diamond,10,11,
Coal,21,21,
How to add string at the end of line containing “Diamond”?
What I have is code that can add string at the end of a file but don’t know how to make it to add that string in specyfic line:
$function_Result = mysql_fetch_row($function_Ask, 0);
$file_To_Edit = "item_Data.csv";
$opened_File = fopen($file_To_Edit, 'w') or die("Error. Code:2 - Can not open file $file_To_Edit");
$string_Data = $function_Result[0] . ",";
fwrite($opened_File, $string_Data);
fclose($opened_File);
I should have used an
preg_replaceif the file content isn’t too large.