In Ruby (PHP is probably close), I would do this with
string_without_numbers = string.gsub(/\b\d+\b/, '')
where the part between // is a regular expression, and \b indicates the word boundary. Note that this would turn "hi 123 foo" into "hi foo" (note: there must be two spaces between words). If words are separated by spaces, you can use
string_without_numbers = string.gsub(/ \d+ /, ' ')
which replaces each sequence of numbers surrounded by two spaces, one space. This may leave numbers at the end of the line, which may not be what you intend.
source share