Skip to content

Instantly share code, notes, and snippets.

@umidjons
Last active December 19, 2015 19:38
Show Gist options
  • Select an option

  • Save umidjons/6007638 to your computer and use it in GitHub Desktop.

Select an option

Save umidjons/6007638 to your computer and use it in GitHub Desktop.
Clean & convert value from non numeric 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