public static function replaceNth($subject, $search, $replace, $nth)
{
$found = preg_match_all('/' . $search . '/', $subject, $matches, PREG_OFFSET_CAPTURE);
if (false !== $found && $found > $nth) {
return substr_replace($subject, $replace, $matches[0][$nth][1], mb_strlen($search));
}
return $subject;
}