Forum Moderators: coopster

Message Too Old, No Replies

Replace Number Range

         

askeli

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

10+ Year Member



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

mincklerstraat

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

WebmasterWorld Senior Member 10+ Year Member



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);

askeli

1:13 pm on Jan 23, 2005 (gmt 0)

10+ Year Member



hi, thanks for that it works perfectly

cheers