Hey everyone,
Is there a native PHP function that strips commas, dots and spaces from a number?
for example the number 1,000.25 should become 1000.25
many thanks
Andy
| SitePoint Sponsor |
Hey everyone,
Is there a native PHP function that strips commas, dots and spaces from a number?
for example the number 1,000.25 should become 1000.25
many thanks
Andy

<?php//Kyle Wolfeecho devBlog("My Dev Notes");
Hmm this doesn't seem to work. I have a variable "fl_area" that produces a text with a comma 1,025 but the function to convert it to feet needs the comma to be removed for the conversion to be successful.
Code:metersToFeetInches( number_format(get_field( "fl_area" ), 2, '.', '') );

Ah I see, try to make it a habit to store your "numbers" as such, without commas, you can always format then with them using number_format later.
Code PHP:$string = '1,600.45'; $number = (double)str_replace(",", "", $string);
Code PHP:metersToFeetInches((double)str_replace(",", "", $fl_area));
<?php//Kyle Wolfeecho devBlog("My Dev Notes");
Bookmarks