views:

122

answers:

2

I have a string that contains unwanted numbers ( any number higher than 5000 )

I want a php function to remove any number higher than 5000.

thnx :)

+7  A: 

PHP < 5.3:

preg_replace_callback('/\s*\d+\s*/', create_function('$a', 'return trim($a[0]) > 5000? " " : $a[0];'), $input);

PHP >= 5.3 (closure support):

preg_replace_callback('/\s*\d+\s*/', function ($a) {
    return trim($a[0]) > 5000? " " : $a[0];
}, $input);
Matt
A: 
preg_replace('/\b0+((?!5000)[5-9]\d{3}|[1-9]\d{4,})(\.\d+)?/', '', $string);
soulmerge
thx, fixed ....
soulmerge
This doesn't replace anything for me..
Matt
thanx Matt .. thanx for your help .. it's ok :)soulmerge .. thanx for your help , but the code didn't work
cash