[lang-ref] ( replace_first ) ( php )

<?php
public function testReplaceFirst(): void
{
	// preg_replace($quoted_pattern, $after, $text, limit: 1)
	$text_org = "abc def ghi\nabc def ghi";
	$s_org = 'def';
	$s_new  = '!!DEF!!';

	$pattern = '/' . preg_quote($s_org, '/') . '/';
	$text_new = preg_replace($pattern, $s_new, $text_org, 1);

	$this->assertNotFalse($text_new);
	$this->assertSame("abc !!DEF!! ghi\nabc def ghi", $text_new);
}