Question:

How do I filter numbers out of a string using PHP?

by  |  earlier

0 LIKES UnLike

How do I filter numbers out of a string using PHP?

 Tags:

   Report

2 ANSWERS


  1. This is an example of a regular expression being used to replace certain characters.

    $str = preg_replace("/[0-9]+/", '', $str);


  2. You can do it with regular expressions, or you can do it with 10 str_replace calls, or you can use this:

    function filter_nums($str)

    {

    for($i = 0; $i<strlen($str); ++$i) if(!ctype_digit($str[$i]) )$out.=$str[$i];

    return $out;

    }

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.