删除阿拉伯音调符号 [英] Remove Arabic Diacritic

查看:97
本文介绍了删除阿拉伯音调符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望php将其转换...

I want php to convert this...

Text : الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ
converted to : الحمد لله رب العالمين 

我不确定从哪里开始以及如何做.绝对不知道.我进行了一些研究,发现此链接 http ://www.suhailkaleem.com/2009/08/26/remove-diacritics-from-arabic-text-quran/,但未使用php.我想使用php并将上述文本秘密转换为转换后的文本.我想从用户输入的阿拉伯文字中删除任何变音符号

I am not sure where to start and how to do it. Absolutely no idea. I have done some research, found this link http://www.suhailkaleem.com/2009/08/26/remove-diacritics-from-arabic-text-quran/ but it is not using php. I would like to use php and covert the above text to converted text. I want to remove any diacritic from user input arabic text

推荐答案

阿拉伯语中的元音变音符号是组合字符,意味着对这些内容的简单搜索就足够了.不必为每个可能的元音的每个可能辅音制定替换规则,这有点乏味.

The vowel diacritics in Arabic are combining characters, meaning that a simple search for these should suffice. There's no need to have a replace rule for every possible consonant with every possible vowel, which is a little tedious.

这是一个工作示例,可以输出您所需的内容:

Here's a working example that outputs what you need:

header('Content-Type: text/html; charset=utf-8', true);
$string = 'الْحَمْدُ لِلَّهِ رَبِّ الْعَالَمِينَ';

$remove = array('ِ', 'ُ', 'ٓ', 'ٰ', 'ْ', 'ٌ', 'ٍ', 'ً', 'ّ', 'َ');
$string = str_replace($remove, '', $string);

echo $string; // outputs الحمد لله رب العالمين

这里重要的是$remove数组.看起来很奇怪,因为'引号之间有一个组合字符,因此它会修改那些单引号中的一个.可能需要保存与文本相同的字符编码.

What's important here is the $remove array. It looks weird because there's a combining character between the ' quotes, so it modifies one of those single quotes. This might need saving in the same character encoding as your text is.

这篇关于删除阿拉伯音调符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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