Skip to content

Instantly share code, notes, and snippets.

@gerald-drissner
Last active October 20, 2022 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gerald-drissner/c05bfe65685268508c6b4c6897c76fb8 to your computer and use it in GitHub Desktop.
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.
/*
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