I have a CSV file that has 7 fields. One of the fields has a number, and some of the numbers start with a "S". If that number start with a "S", I want to strip it off. I am not sure how to do that. I first wrote the script to open the file, load each line into an array and split the array by field. Then split the variable where there is a "S". The problem showed up when there is another "S" in the field. I only want to split the first "S" at the beginning of the field. Isn't there an additional value to add to the split function that will only split by the qualifier once.
Here is what I have now. <?php $OutputFile = fopen("2ndrun.txt", "w") or die("Can't open File"); fwrite($OutputFile, "\"Contract\",\"PN\",\"SN\",\"Uin\",\"Type\",\"Descrip\",\"Qty\",\"Ship Date\"\n"); $fp = fopen ("original.txt","r"); $Row = 1; while($data = fgetcsv($fp, 1000, ",")) { if($Row != 1) { //"Contract","PN","SN","Uin","Type","Descrip","Qty","Ship Date" fwrite($OutputFile, "\"$data[0]\",\"$data[1]\","); list($SN1, $SN2) = split("S", $data[2]); fwrite($OutputFile, "\"$SN2\",\"$data[3]\",\"$data[4]\",\"$data[5]\",\"$data[6]\",\"$data[7]\"\n "); } $Row++; } fclose ($fp); fclose ($OutputFile); print "Done!\n"; ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php