Posted By

Tate on 04/08/08


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

silentbob84
djordjes


Remove everything but numbers from a string


 / Published in: PHP
 

Make it $newstring = eregreplace("[^A-Za-z0-9]", "", $string );

  1. $string = "(032)555-5555";
  2. $new_string = ereg_replace("[^0-9]", "", $string );
  3. echo $new_string;

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: funktifyknow on April 19, 2008

try replacing the second line with the following:

$newstring = pregreplace('[\D]', '', $string);

It is slightly shorter, and a bit faster.

You need to login to post a comment.