We have the following test code.
$subject = "Мама мыла раму, дочь чертила пентаграмму"; $array = array( 'Мама', 'Мама мыла', 'Мама мыла раму', 'Мама мыла раму, дочь', 'Мама мыла раму, дочь чертила', ); $array_pattern = array(); foreach ($array as $value) { $array_pattern[] = "#^{$value}#i"; } $result = preg_replace($array_pattern, '', $subject); echo $result; As a result, we get a string of soap frame, the daughter drew a pentagram instead of the desired string pentagram . How to change the behavior of preg_replace in this case?
PS The question is related to this topic .