Skip to content

Instantly share code, notes, and snippets.

@BrElio
Forked from gerald-drissner/searchwp_removearabic.php
Last active July 22, 2025 09:35
Show Gist options
  • Select an option

  • Save BrElio/9bc2d96720ff147e5cdcad06354a9709 to your computer and use it in GitHub Desktop.

Select an option

Save BrElio/9bc2d96720ff147e5cdcad06354a9709 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.
<?php
/*
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( $string ) {
$remap = [
'إ' => 'ا',
'آ' => 'ا',
'أ' => 'ا',
'ئ' => 'ى',
'ة' => 'ه',
'ؤ' => 'و',
'ـ' => '',
'آ' => 'ا',
];
$diacritics = [
'~[\x{0600}-\x{061F}]~u',
'~[\x{063B}-\x{063F}]~u',
'~[\x{064B}-\x{065E}]~u',
'~[\x{066A}-\x{06FF}]~u',
];
$string = preg_replace( $diacritics, '', $string );
$string = str_replace( array_keys( $remap ), array_values( $remap ), $string );
return $string;
}
@hanicker
Copy link

@BrElio ciao, grazie per lo script, sarebbe possibile contattarti per una consulenza?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment