Reputation: 3783
The following code will turn 1000 into 1,000:
$price = '1000';
$price2 = number_format($price);
echo $price2;
How would I turn 1,000 into 1000? I'm guessing it would be something along the lines of this:
$price = '1,000';
$price2 = remove_format($price);
echo $price2;
Upvotes: 2
Views: 12612
Reputation: 841
I haven't tested it, but I'd use something like this:
$a = "1,000";
$b = str_replace( ',', '', $a );
if( is_numeric( $b ) ) {
$a = $b;
}
Upvotes: 0
Reputation: 1276
It's something that is very simple, but I'll make it into a function for you.
You can do this by just using something like the str_replace() function to remove the ,
this is what I came up with:
Code:
function remove_format($text){
$text = str_replace(",", "", $text)
return $text;
}
Upvotes: 8