Remove £ Before Entering Database

Hi all, having a slight problem, I’m created an ordering system and looping through the products added to enter them into the database (working perfectly). Problem is, if someone accidentally enters a £ in the product total, it’s upsetting things. How can I remove the £ sign? Tried the following but no luck. Any help is appreciated as always :smiley:

  			//Enter Products into DB
			 foreach($_POST['products'] as $id=>$product){
				$blip = preg_replace('/^\\£/', '', $product['price']);
					$total = $blip*$product['quantity'];
						$total;
					
			//Push Data into Database					
			$sql = "INSERT INTO order_products (receipt_id, customer_id, product_name, product_price, product_quant, product_serial, product_code, sub_total) VALUES ('$_POST[receiptno]','$_GET[id]','$product[name]','$blip','$product[quantity]','$product[serial]','$product[stock]','$total')";
			mysql_query($sql);
			 }
			 $addDet = "INSERT INTO orders (addedby, receipt_id, date_added, del_method, courier, spec_instr, cust_ref, date_dispatched, delivery_costs, part_exchange, vat_info, three_month_warranty) VALUES ('$_SESSION[SESS_LOGIN]','$_POST[receiptno]',now(),'$_POST[delmethod]', '$_POST[courier]', '$_POST[specialinst]','$_GET[id]', '$_POST[dispatched]', '$_POST[postage]', '$_POST[pxvalue]', '$_POST[vatInfo]', '$_POST[warranty]')";
			 mysql_query($addDet);

	}

  $blip = str_replace('£', '', $product['price']); 

Try that?

Hi there, it’s kind of working. Though now instead of display a £ in the database and when echoing out I’m getting �. Any ideas?

Run a utf8_decode on the output, perhaps maybe even on the way in?

http://php.net/manual/en/function.utf8-decode.php

Try on the output first.

Hey dude, I’ve just tried it, doesn’t seem to be making any difference! Gerrr!

I assume you have a £ in your echo command; try replacing the £ with £

Hey Rubble, I don’t have access to my files at the moment until tomorrow morning, will let you know if I have any luck. Cheers for the post, it could well be to use £ :smiley:

Is it not true that what you want to filter out is anything which is not a number between 0 and 9 and a dot?

Or maybe you are storing just pennies and do not even need the dot?


$string = "£1.00" ;
// Remove all non numeric characters except a dot
 $a =  preg_replace('/[^0-9\\.]/', '', $string);
echo $a ;
// Gives 1.00

Why do you even allow non-floating point numbers to be sent to the db? It’s easy to validate for the total and whether it’s larger than 0 or not.

Hey Cups, that’s perfect, worked an absolute treat. Just what I needed. I’m storing the data as a decimal(10,2) in the database - I think this is an acceptable method of storage?