virtuexru Posted December 29, 2008 Share Posted December 29, 2008 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 Link to comment https://forums.phpfreaks.com/topic/138747-solved-how-can-i-strip-5000-to-just-5000/ Share on other sites More sharing options...
Mchl Posted December 29, 2008 Share Posted December 29, 2008 $stripped = str_replace(array("$",","),"","$24,900"); should work, but I did not test it... if it doesn't look in the manual for str_replace to go other way you can use money_format Quote Link to comment https://forums.phpfreaks.com/topic/138747-solved-how-can-i-strip-5000-to-just-5000/#findComment-725434 Share on other sites More sharing options...
UpcomingPhpDev Posted December 29, 2008 Share Posted December 29, 2008 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 Link to comment https://forums.phpfreaks.com/topic/138747-solved-how-can-i-strip-5000-to-just-5000/#findComment-725435 Share on other sites More sharing options...
effigy Posted December 29, 2008 Share Posted December 29, 2008 Store and work with the number in its digit form, using number_format for its display. Quote Link to comment https://forums.phpfreaks.com/topic/138747-solved-how-can-i-strip-5000-to-just-5000/#findComment-725461 Share on other sites More sharing options...
virtuexru Posted December 29, 2008 Author Share Posted December 29, 2008 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 . Quote Link to comment https://forums.phpfreaks.com/topic/138747-solved-how-can-i-strip-5000-to-just-5000/#findComment-725469 Share on other sites More sharing options...
virtuexru Posted December 29, 2008 Author Share Posted December 29, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/138747-solved-how-can-i-strip-5000-to-just-5000/#findComment-725471 Share on other sites More sharing options...
premiso Posted December 29, 2008 Share Posted December 29, 2008 money_format is the key if you are on a linux box. Of not view the comments for a user-created money_format function. Quote Link to comment https://forums.phpfreaks.com/topic/138747-solved-how-can-i-strip-5000-to-just-5000/#findComment-725474 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.