Replace only first match using preg_replace [duplicate] March 9, 2023 by Tarik The optional fourth parameter of preg_replace is limit: preg_replace($search, $replace, $subject, 1);