An example of what I need:
$input = "bar bar bar bar bar";
$result = preg_replace_callback('bar', 'foo', $input); // And there must be some way to limit preg_replace_callback so that it replaces only the first 2 (for example) matches of the expression
echo $result;
Result: foo foo bar bar bar
Tried google it but didn't find anything. Sorry, I'm new to php.