str_replace replaces all occurrences of a word with a replacement.
preg_replace replaces occurrences of a pattern with a replacement and ta
This is an enhanced version of @brad-christie's answer which ads compatibility for arrays as $find and $replace values:
function str_replace_limit($find, $replacement, $subject, $limit = 0) {
if ($limit == 0)
return str_replace($find, $replacement, $subject);
for ($i = 0; $i < count($find); $i++) {
$find[$i] = '/' . preg_quote($find[$i],'/') . '/';
}
return preg_replace($find, $replacement, $subject, $limit);
}