$s='цкнгшщзхфвпрлджчсмтб'; $test=$s[rand(0,19)].$s[rand(0,19)]; echo $test; 

UTF-8 file without Bohm. In HTML it is signed that UTF-8 too. Derived Kracolzjabra.

  • then what error is displayed? - Artem
  • No errors are output, the text is displayed in an incomprehensible encoding, such as: ш - jkeks

2 answers 2

 <? $s='цкнгшщзхфвпрлджчasdб'; $test=mb_substr($s, rand(0,19), 1, 'utf-8').mb_substr($s, rand(0,19), 1, 'utf-8'); echo $test; ?> 

What did you want when choosing bytes from a string in UTF8?)

  • Duck is scary because now to live, I thought how a person would work with letters .. apparently you used PEAR .. - jkeks
  • Long Mlyn wrote the answer :( Youre ahead. - Artem
  • @jkeks have such a thing and others like it) Not so scary. - Sh4dow

well then look

In UTF-8 encoding, 1 character takes 2 bytes and what you get is displayed correctly.

 $s[rand(0,19)] 

This will output only part of the character. :) rewrite the code and read how UTF-8 differs from windows-1251

  • not logical in theory ... I want 10 characters, but it shoots me the 10th byte. - jkeks 4:39 pm
  • that's why he and UTF-8 to be able to on the site, let's say have multilingualism for a large number of languages ​​:) - Artem