Welcome to WebmasterWorld Guest from 18.206.194.210

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Replace Number Range

     
10:00 am on Jan 23, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 29, 2003
posts:94
votes: 0


Hi is it possible to replace a range of numbers in a string with a word rather than str_replace one at a time?

ie
replace 1150 => 2650 with widget

Can some one point me in the right direction please?

Cheers

10:48 am on Jan 23, 2005 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Mar 19, 2003
posts:1001
votes: 0


One way you could do it is along these lines:


function in_range($arr){
if($arr[1] > 1150 && $arr[1] < 2650) return 'widget';
else return $arr[1];
}
$content = preg_replace_callback('#([0-9]{4})#', 'in_range', $content);
1:13 pm on Jan 23, 2005 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 29, 2003
posts:94
votes: 0


hi, thanks for that it works perfectly

cheers