Last active
October 20, 2022 11:58
-
-
Save gerald-drissner/c05bfe65685268508c6b4c6897c76fb8 to your computer and use it in GitHub Desktop.
Removes all kind of Arabic diacritical signs and markers and replaces them with their plain letter form. For the use of SearchWP Wordpress plugin.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Plugin Name: SearchWP Remove Arabic Diacritics | |
Description: Removes all kind of إعراب-signs as well as تشكيل-signs for the use of SearchWP Wordpress plugin. | |
Author: Gerald Drissner | |
Note: This is a fork and extension of https://gist.github.com/BrElio/bd84d8035278adf834b29ec5e1187567 and Relevannsi's code snippet regarding foreign languages. | |
Version: 1.0.0 | |
Last update: 2022-10-20 | |
*/ | |
add_filter( 'searchwp\tokens\string', 'swp_arabic_remap', 9); | |
function swp_arabic_remap( $a ) { | |
$remap = array( | |
'إ' => 'ا', | |
'آ' => 'ا', | |
'أ' => 'ا', | |
'ئ' => 'ى', | |
'ة' => 'ه', | |
'ؤ' => 'و', | |
'ـ' => '', | |
'آ' => 'ا', | |
); | |
$diacritics = array( | |
'~[\x{0600}-\x{061F}]~u', | |
'~[\x{063B}-\x{063F}]~u', | |
'~[\x{064B}-\x{065E}]~u', | |
'~[\x{066A}-\x{06FF}]~u', | |
); | |
$a = preg_replace( $diacritics, '', $a ); | |
$a = str_replace( array_keys( $remap ), array_values( $remap ), $a ); | |
return $a; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment