Stripping a string of its non-numeric characters June 4, 2023 by Tarik With a regexp. Specifically, use the preg_replace function: $phone = preg_replace('/\D+/', '', $phone);