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

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

问题描述

我想让 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天全站免登陆