Forked from gerald-drissner/searchwp_removearabic.php
Last active
July 22, 2025 09:35
-
-
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.
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
| <?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; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@BrElio ciao, grazie per lo script, sarebbe possibile contattarti per una consulenza?