Snippets v2

Languages
My Snippets

Strip all characters out that are not numeric Login or Register to Bookmark this snippet

Description PHP

This function strips out all characters that are not numeric for a given string.

The Code Download
  1. <?php
  2.  
  3. function numericOnly($string) {
  4.     //function to strip characters other than numerals from a string
  5.     $numString = ereg_replace("[^[:digit:]]", "", $string);
  6.     return $numString;
  7. }
  8.  
  9.  
  10. //usage
  11. $string = "f9s9848d8f--432-d4";
  12. $string = numericOnly($string);
  13. echo $string; //echos 9984884324
  14.  
  15. ?>
Credits Contact JC

Added by JC on 12th November, 2007

Comments

There are no comments about this snippet.

Post Comment HTML is allowed

You must be registered and logged in to post a comment.

Login here to post a comment