I have a csv file as follows
Head1,Head2,Head3
a,b,c
X1,c,X1
based on the array input, I have to replace the value of X1 to A1. So If array inputs [2,2], the output should be
Head1,Head2,Head3
a,b,c
X1,c,A1
and if array inputs [2,0] my output should be
Head1,Head2,Head3
a,b,c
A1,c,X1
I am replacing X1's with A1 using str_replace but how to I do targeted string replace.
$path_to_file = dirname(__DIR__)."/abc.csv";
$file_contents = file_get_contents($path_to_file);
$file_contents = str_replace("X1","A1",$file_contents);
file_put_contents($path_to_file,$file_contents);
X1withA1? If yes do you want to replace everything there withA1or only if it isX1?