PHP:将特定波斯尼亚字符转换为非波斯尼亚字符(utf8 标准字符) [英] PHP: Convert specific-Bosnian characters to non-bosnian (utf8 standard chars)

查看:9
本文介绍了PHP:将特定波斯尼亚字符转换为非波斯尼亚字符(utf8 标准字符)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在波斯尼亚,我们有以下字符仅在波斯尼亚和克罗地亚以拉丁形式使用,因此我需要将这些字母转换如下:

FROM |到ć |C| |Cž |z| |秒đ |DJ

如果使用某种特殊形式的 RegEx 或 utf8_encode/decode 可以做到这一点,那么将非常欢迎该信息和适当的示例!谢谢大家.

PS - 想用 PHP 来实现!

解决方案

您可以将其与 iconv 一起使用.

$result = iconv("UTF-8", "ASCII//TRANSLIT", $text);

假设您的输入 $text 是 utf-8,这将起作用.如果它在 latin-1 中,则使用

iconv("ISO-8859-1", "ASCII//TRANSLIT", $text);

因为您的 PHP 必须有 iconv 扩展名,通常 iconvphp.ini 文件中启用,但并非总是如此.

In Bosnia we have following characters only used in latin-form in Bosnia and Croatia, so I'd need to convert these letters as following:

FROM | TO
  ć  | c
  č  | c
  ž  | z
  š  | s
  đ  | dj

If this is possible with some special form of RegEx, or utf8_encode/decode, that informatiion and an appopriate example will be quite welcome! Thanks all.

PS - Want to achive this in PHP!

解决方案

You can use this with iconv.

$result = iconv("UTF-8", "ASCII//TRANSLIT", $text);

That will work assuming your input $text is in utf-8. If it's in latin-1 then use

iconv("ISO-8859-1", "ASCII//TRANSLIT", $text);

Of cause your PHP must have iconv extension, most often iconv is enabled in php.ini file, but not always.

这篇关于PHP:将特定波斯尼亚字符转换为非波斯尼亚字符(utf8 标准字符)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆