title: PHP to replace 2 character at nth position in an string
body: <p>I am developing bilingual website in codeignitor and i have created language files. All works fine except when switching the language i want to replace the language abbraviation in the url at 31th and 32th position starting at 0.</p>
  <p>English Url :</p>
  <blockquote>
  <p>$url=http://localhost/abc/index.php/<strong>en</strong>/news/title/new-version-of-goldendict-with-dzongkha</p>
  </blockquote>
  <p>Dzongkha Url :</p>
  <blockquote>
  <p>$url=http://localhost/abc/index.php/<strong>dz</strong>/news/title/new-version-of-goldendict-with-dzongkha</p>
  </blockquote>
  <p>i just want php to change <strong>en</strong> to <strong>dz</strong></p>
  <p>i tried</p>
  <blockquote>
  <p>$url=http://localhost/abc/index.php/<strong>en</strong>/news/title/new-version-of-goldendict-with-dzongkha</p>
  <p>$lang_id='dz';</p>
  <p>$old_lang=substr($url, 31, 2);</p>
  <p>$newurl = str_replace($old_lang,$lang_id,$url );</p>
  </blockquote>
  <p>However above codes changes dz to en but also replaces 45 and 46 character. This is what happens after conversion.</p>
  <blockquote>
  <p>$url=http://localhost/abc/index.php/<strong>dz</strong>/news/title/<strong>dz</strong>w-version-of-goldendict-with-dzongkha</p>
  </blockquote>
  <p>Any one who has an idea whats happening</p>