I have this function

function displayOrderList()
{
        $path = "file.csv";
	$file = fopen($path,"r");
	$row = 0;
	while (($column = fgetcsv($file,1024," "))!== false)
	{
  	$row++;
	$price = $column[0];
	$product =$column[1];
	$productid = $column[2];
			
	$price_id ="price".$row;
	$qty_id = "qty".$row;
	$total_id = "total".$row;
			
        echo "<tr align=center>
	          <td><input type=\"text\"  name=\"qty[]\" id=\"".$qty_id."\" value=\"0\" size=\"5\" onkeyup=\"get_total(this.id,'$price_id','$total_id')\" /></td>
	        <td id=\"price\"><input type=\"text\" class=\"product\" disabled id=\"".$price_id."\" value=".$price." /></td>
	           <td><input type=\"text\" class=\"product\" disabled value=\"".$product."\" /></td>	
	  	<td><input type=\"text\" class=\"product\" disabled value=\"".$productid."\" /></td>
	  	<td><input type=\"text\" class=\"product\" readonly name=\"total[]\" id='$total_id' title=\"total\" value=\"0\" /></td> 			                </tr>
	    <input type=hidden name=\"price[]\" value=\"".$price."\" />
	     <input type=hidden name=\"product[]\" value=\"".$product."\" />
	    <input type=hidden name=\"productid[]\"\" value=\"".$productid."\" />
						";
		}
	echo "	  
		  <tr>
		 	<td colspan=4 align=right>Grand Total:$</td>
		  	<td><input type=\"text\" readonly class=\"product\" name=\"overall\" id=\"overall\" value=\"0\"/></td>
	 	  </tr>
	 	  <tr>
 	  	<td colspan=\"5\" align=center id=\"submit\"><input type=\"submit\" value=\"Order\"/></td>
         	  </tr> 
		  </table></center>
				  ";
          fclose($file);
	}

but the output of this function has commas at the end in each item which is very annoying coz I cannot compute the total = quantity x price

if i have a csv file with content

Price | Product | ProducID

40.25, Product1, 1111111

Output in the table is like this:
column1 column2 column3
40.25, Product1, 1111111,

All I want to is to get rid of the commas or replaced the comma with whitespace.

line six while (($column = fgetcsv($file,1024," "))!== false) tells the parser to separate coulmns at the space character which includes the comma as data while (($column = fgetcsv($file,1024,','))!== false) (comma)

or while (($column = fgetcsv($file,1024))!== false) (default)

should work
reference http://php.net/manual/en/function.fgetcsv.php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.