php - CSV row override -


so have problem need able override specific row in csv file.

so far have:

$myfile = fopen("targets.csv", "a") or die ("unable open file!"); $txt = $name . "," . $insights . "," . $nbc . "," . $poc . "," . $fhc . "," . $lender . "," . $fhcc . "\n"; fwrite($myfile, $txt); fclose($myfile);  $csv = array_map('str_getcsv', file('targets.csv')); // line puts csv data , array! $arrlength = count($csv); 

a friend , tried this:

$add = true;  ($i=0; $i<$arraylength; $i++)  {   if ($csv[i][0] == $name);     $add = false;     $file = str_replace($csv[i],_____ , $file);      break;   if ($add == true) {     add[$name, $insights, $nbc, $poc, $fhc, $lender, $fhcc];  } 

and 1 of teachers said this, have no idea how it?

str_replace looks value (or text) in string , replaces new information.

you have couple options.

set string variable run function.

if 2d array can use search array, find value use str replace change value.

at moment, every time submit data creates new line person's name, , have code searches specific name in csv, problem if have multiple lines same name.

any appreciated.

cheers, zach


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -