title: Calculating the length of a Japanese multibyte string with half-width kana in PHP
body: <p>So I have a UTF-8 encoded string which can contain full-width kanji, full-width kana, half-width kana, romaji, numbers or kawaii japanese symbols like ★ or  ♥.</p>
  
  <p>If I want the length I use <code>mb_strlen()</code> and it counts each of these as 1 in length. Which is fine for most purposes.</p>
  
  <p>But, I've been asked (by a Japanese client) to only count half-width kana as 0.5 (for the purpose of maxlength of a text field) because apparently thats how Japanese websites do it. I do this using <code>mb_strwidth()</code> which counts full-width as 2, and half-width as 1, then i just divide by 2.</p>
  
  <p>However this method also counts romaji characters as 1 so something like <code>Chocｱｲｽ</code> would count as 7 .. then i'd divide by 2 to account for kanji and I'd get 3.5. but I actually want 5.5 (4 for the Romaji + 1.5 for the 3 half-width kana).</p>
  
  <p>// EDIT:
  some more info: any character (even non-kana) which has both a full and a half should be 1 for the full-width and 0.5 for the half-width. for example, characters like <code>￥、３＠（</code> should all be 1, but characters like <code>¥,3@(</code> should all be 0.5</p>
  
  <p>// EXTRA EDIT: symbols like ☆ and ♥ should be 1, but the mb_strwidth/2 method return them as 0.5</p>
  
  <p>Is there a standard way that Japanese systems count string length?
  Or does everyone just loop thru their strings and count the characters which don't match the standard width rules?</p>