Forum Moderators: coopster
$string = 'Hello, there are 29 messages waiting for you';
$number = preg_replace("/[^0-9]/", '', $string); // ditch anything that is not a number
$number should now be 29.
This is only works properly if there's just one number in the string, otherwise numbers will be concatenated.
I'm sure somebody better than me in regexp can offer a precise regexp to do this. Or you can test yours by searching for an "online regexp" website.
Thanks Ron for the code, I'll look more at that and try to incorporate it!
[edited by: CWebguy at 7:13 pm (utc) on Jan. 7, 2008]