$string = 'Some Text .... 1. 2 .3. Buy'; $string = preg_replace('~[^0-9]+~','',$string); echo $string; // 123