$enc = 'UTF-8'; $word = "РАЗРАБОТАТЬ"; $word = preg_replace('/\s+/', '', $word); $word = mb_convert_case($word, MB_CASE_TITLE, "UTF-8"); $count = mb_strlen($word, $enc); $new_word = mb_substr($word, 0, ($count - 1), $enc); $new_word = $new_word . mb_strtoupper(mb_substr($word,($count - 1), 1, $enc), $enc); $randomLine = $new_word; 

I need the register of the 1st and last letter to be Upper, only the letter r is always displayed as "?"

  • 2
  • In order not to specify "UTF-8" for each mb_ * function, set the encoding for these functions by the function mb_internal_encoding ("UTF-8") at the beginning of the script. Also for all templates that work with UTF-8 add the u modifier: preg_replace ('/ \ s + / u', '', $ word); Try copying the line “DEVELOP” from this page and paste it into your code. - Miron

2 answers 2

1) First, write the PHP file

 header('Content-Type: text/html; charset=utf-8'); 

2) Create a .htaccess file and write in it

 AddDefaultCharset UTF-8 

It is better to use the second method, because the encoding is set for most cases, rather than registering a header each time.

  • forgot to say, the title is encoded in the title - Nikolay Vasilenkov

From comments to php.net documentation

 function mb_strrev($str){ $r = ''; for ($i = mb_strlen($str); $i>=0; $i--) { $r .= mb_substr($str, $i, 1); } return $r; } function mb_ucfirst($str) { $fc = mb_strtoupper(mb_substr($str, 0, 1)); return $fc.mb_substr($str, 1); } $word = "РАЗРАБОТАТЬ"; $result = mb_strrev(mb_ucfirst(mb_strrev(mb_ucfirst(mb_strtolower($word))))); // РазработатЬ