I am Hack Sparrow
Captain of the Internets.

PHP: How to remove Numbers from String

You want to remove all Numbers from a String using PHP

For whatever reason if you are looking to remove all instances of numbers from a string in PHP, use the simple function I deviced below.

function remove_numbers($string) {
    $num = array(1,2,3,4,5,6,7,8,9,0);
    return str_replace($num, '', $string);

Examples of using the number removing function.

echo remove_numbers('123kicks'); //echoes kicks
echo remove_numbers('0t4r45i34c525k345s983!4'); //echoes tricks!

Isn't that cool? If you found the above function useful comment "Thanks Captain!".


  1. PHP str_replace
  2. PHP Arrays

One Response to “PHP: How to remove Numbers from String”

  1. Sam says:

    There is a simpler way: trim($str, ‘0..9’);

Make a Comment