title: PHP: Is it possible to correctly SUBSTR a UTF-8 string?
body: <p>I have (in an SQLite database) the following string: </p>
  
  <p><code>Лампа в вытяжке на кухне меняется, начиная с вытаскивания белого штырька справа.</code></p>
  
  <p>The string is correctly shown by PHP using <code>print</code>. I would like to obtain just the first 50 chars of this string, i.e. </p>
  
  <p><code>Лампа в вытяжке на кухне меняется, начиная с вытас</code>.</p>
  
  <p>I have tried using <strong>both the substr and mb_substr</strong>, and get </p>
  
  <p><code>Лампа в вытяжке на кухне ме�</code>, i.e. only 28 chars. </p>
  
  <p>After reading here and elsewhere about the problems of mbstring, I realise that this is actually a 50 byte string (22 Russian chars = 44 bytes plus 5 spaces plus 1 question symbol). </p>
  
  <p>Is there any nice solution to this? All my strings are UTF-8, so I could of course program a substr-function myself, by checking the first bit of every byte etc. But this should surely have been done before, right?</p>
  
  <p>UPDATE: I believe <code>mb_substr</code> does not work properly because <code>mb_detect_encoding()</code> <a href="https://stackoverflow.com/questions/1846201/">does not work properly</a>. </p>