title: Convert Chinese Pinyin with accents to numerical form
body: <p>I'm looking to convert Pinyin where the tone marks are written with accents (e.g.: Nín hǎo) to Pinyin written in numerical/ASCII form (e.g.: Nin2 hao1).</p>
  
  <p>Does anyone know of any libraries for this, preferably PHP? Or know Chinese/Pinyin well enough to comment?</p>
  
  <p>I started writing one myself that was rather simple, but I don't speak Chinese and don't fully understand the rules of when words should be split up with a space.</p>
  
  <p>I was able to write a translator that converts:</p>
  
  <p><code>Nín hǎo. Wǒ shì zhōng guó rén</code> ==> <code>Nin2 hao3. Wo3 shi4 zhong1 guo2 ren2</code></p>
  
  <p>But how do you handle words like the following - do they get split up with a space into multiple words, or do you interject the tone numbers within the word (if so, where?) :
  <code>huā shíjiān</code>, <code>wèishénme</code>, <code>yuèláiyuè</code>, <code>shēngbìng</code>, etc.</p>