Jump to content

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


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!

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.

 

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.