Extract Numbers from a string


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.