将变音符号替换为

将变音符号替换为

本文介绍了将变音符号替换为“等效” ASCII中的PHP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

相关问题:




在上面的问题中,我在寻找一种可靠,可靠的方法来减少任何unicode字符到近等效ASCII使用PHP。我真的想避免滚动自己的查找表。



例如(从第一个引用的问题偷来): c> c> /ca3.php.net/iconvrel =nofollow noreferrer> iconv 模块可以做到这一点,更具体地说, function:

  $ str = iconv 'Windows-1252','ASCII // TRANSLIT // IGNORE',Gracišce); 
echo $ str;
//输出Gracisce

iconv的主要麻烦是你只需要看看你的编码,但它绝对是正确的工作(我使用'Windows-1252'为例,由于我正在使用的文本编辑器的限制);你确定要使用iconv的功能是 // TRANSLIT 标志,表示iconv将没有ASCII匹配的任何字符转换为最接近的近似值。


Related questions:

  1. How to replace characters in a java String?
  2. How to replace special characters with their equivalent (such as " á " for " a") in C#?

As in the questions above, I'm looking for a reliable, robust way to reduce any unicode character to near-equivalent ASCII using PHP. I really want to avoid rolling my own look up table.

For example (stolen from 1st referenced question): Gračišće becomes Gracisce

解决方案

The iconv module can do this, more specifically, the iconv() function:

$str = iconv('Windows-1252', 'ASCII//TRANSLIT//IGNORE', "Gracišce");
echo $str;
//outputs "Gracisce"

The main hassle with iconv is that you just have to watch your encodings, but it's definitely the right tool for the job (I used 'Windows-1252' for the example due to limitations of the text editor I was working with ;) The feature of iconv that you definitely want to use is the //TRANSLIT flag, which tells iconv to transliterate any characters that don't have an ASCII match into the closest approximation.

这篇关于将变音符号替换为“等效” ASCII中的PHP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-29 02:46