Jump to content

[SOLVED] How can I strip "$5,000" to just "5000"?


virtuexru

Recommended Posts

Or any number in that format like $24,900 to just 24900. Then turn it back? I need to make a script that will take a price and automatically add a certain amount like $24,900 should be $26,900 but I need to strip the numbers before I can use the addition function.

 

Any ideas? Thank you!

  Quote

Or any number in that format like $24,900 to just 24900. Then turn it back? I need to make a script that will take a price and automatically add a certain amount like $24,900 should be $26,900 but I need to strip the numbers before I can use the addition function.

 

Any ideas? Thank you!

 

You could just use a simple replace

 

<?php

$Number = str_replace(",","",$Number);
$Number = str_replace("$","",$Number);

?>

 

If you have more things to remove, Just place them in a array and call str_replace once.

 

  Quote

  Quote

Or any number in that format like $24,900 to just 24900. Then turn it back? I need to make a script that will take a price and automatically add a certain amount like $24,900 should be $26,900 but I need to strip the numbers before I can use the addition function.

 

Any ideas? Thank you!

 

You could just use a simple replace

 

<?php

$Number = str_replace(",","",$Number);
$Number = str_replace("$","",$Number);

?>

 

If you have more things to remove, Just place them in a array and call str_replace once.

 

 

This worked :). Thanks. I know its not the most creative method but it did the trick :).

But now here is the real question, here is my code:

 

		$o_price = $row['_price'];

		$o_price = str_replace(",","",$o_price);
		$o_price = str_replace("$","",$o_price);

		$price   = $o_price + 5000;
		$price   = "$".$price;

 

How should I go about getting the "," back in the right location.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.