我正在codeignitor中开发双语网站,并且已经创建了语言文件。一切正常,除了切换语言时,我想替换从0开始在第31和32位置的url中的语言缩写。
英文网址:
$ url = http://localhost/abc/index.php/ zh -CN / news / title / new-version-of-goldendict-with-dzongkha
宗卡网址:
$ url = http://localhost/abc/index.php/ dz / news / title / new-version-of-goldendict-with-dzongkha
我只想要php将en更改为dz
我试过了
$ url = http://localhost/abc/index.php/ zh -CN / news / title / new-version-of-goldendict-with-dzongkha
$ lang_id ='dz';
$ old_lang = substr($ url,31,2);
$ newurl = str_replace($ old_lang,$ lang_id,$ url);
但是,以上代码将dz更改为en,但也替换了45和46个字符。这就是转换后发生的情况。
$ url = http://localhost/abc/index.php/ dz / news / title / dz w-version-of-goldendict-with-dzongkha
任何一个知道发生了什么事的人
试试这个 -
$url="http://localhost/abc/index.php/en/news/title/new-version-of-goldendict-with-dzongkha";
echo $str = substr_replace($url,'dz',31,2);
希望这会帮助你。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句