I am trying to trim the endings, but unfortunately it does not work. The problem is in UTF-8, tell me how to solve the problem? Instead of the cropped word at the exit, I get the word at the end of the gibberish.

$znach = 'тестовое'; $znach = trim($znach); $reg = "/\.|,|!|\?/i"; $znach = preg_replace($reg,'',$znach); $reg = "/[ый|ой|ая|ое|ые|ому|а|о|у|е|ого|ему|и|ство|ых|ох|ия|ий|ь|я|он|ют|ат]$/"; $znach = preg_replace($reg,'',$znach); 
  • add /../iu , if the case is in the encoding - splash58

1 answer 1

u flag to help.

 /(ый|ой|ая|ое|ые|ому|а|о|у|е|ого|ему|и|ство|ых|ох|ия|ий|ь|я|он|ют|ат)$/u 

php initially doesn’t hold unicode unless it is told otherwise. https://secure.php.net/manual/en/reference.pcre.pattern.modifiers.php u (PCRE_UTF8)

And yes, in the sense instead of a range, alternatives are needed - the brackets are not square, but round.

  • Gorgeous like it worked !! )) Thank!! - alexsis20102