Last active
December 19, 2015 19:38
-
-
Save umidjons/6007638 to your computer and use it in GitHub Desktop.
Clean & convert value from non numeric characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <? | |
| // clean $field value from non numeric characters | |
| $field = "234.345g"; | |
| echo $field . '<br>'; // 234.345g | |
| $fieldFloat = floatval( preg_replace( '/[^-0-9\.]/', "", $field ) ); // 234.345 | |
| $fieldInt = intval( preg_replace( '/[^-0-9]/', "", $field ) ); // 234 | |
| echo $fieldFloat . '<br>'; | |
| echo $fieldInt . '<br>'; | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment