Код: Выделить всё
// should match, replace, and output: user/profile/foo
$string = 'user/foo';
echo preg_replace('#^user/(?P[^/]+)$#Di', 'user/profile/(?P=id)', $string);
Подробнее здесь: https://stackoverflow.com/questions/525 ... eg-replace
Код: Выделить всё
// should match, replace, and output: user/profile/foo
$string = 'user/foo';
echo preg_replace('#^user/(?P[^/]+)$#Di', 'user/profile/(?P=id)', $string);