preg_replace() /e

Код:
$text = preg_replace_callback ( "#\{date=(.+?)\}#i", function($matches) use($row) {
    return langdate($matches[1], $row['date'], false);
}, $text);
 
function preg_replace_nth($pattern, $replacement, $subject, $nth=1) {
return preg_replace_callback($pattern,
function($found) use (&$pattern, &$replacement, &$nth) {
$nth--;
if ($nth==0) return preg_replace($pattern, $replacement, reset($found) );
return reset($found);
}, $subject,$nth );
}

echo preg_replace_nth("/(\w+)\|/", '${1} is the 4th|', "|aa|b|cc|dd|e|ff|gg|kkk|", 4);
 
Назад
Сверху