Posted By

carbonr on 10/26/10


Tagged

php number String


Versions (?)

Extract Numbers from a string


 / Published in: PHP
 

Will help convert string to number OR get number in a selected string.

  1. <?php
  2. // extract numbers from a string
  3.  
  4. $string = "The 1. Quick and 2. Brown fox said 3. (!@*(#!@*";
  5.  
  6. $new_string = ereg_replace("[^0-9]", "", $string);
  7.  
  8.  
  9. echo $new_string;
  10. // output: 123
  11. ?>

Report this snippet  

You need to login to post a comment.