Forum Moderators: coopster
[pre]
$string = "I want to go to the store and from there I want to get some coffee.
After that I want to make iced coffee and then I'll make some more coffee.";
#
#1 out of x (where x is $num) just note that it replaces the last instance (every 3rd in this case)
$num = 3;
#
$from = 'want';
$to = 'need';
#
$count = 1;
function callback($matches) {
global $num;
global $count;
global $to;
#
if($count == $num) {
$count = 1;
return $to;
} else {
$count++;
return $matches[0];
}
}
#
$pattern = "/".[url=http://www.php.net/preg-quote]preg_quote[/url]($from)."/i";
echo [url=http://www.php.net/preg-replace-callback]preg_replace_callback[/url]($pattern,'callback',$string);
[/pre] Good luck :)
>>I wish I could offer more advice to users on this forum.
Learn as much as you can now and give back what you can later. It doesn't have to happen all at once :)