Skip to content

Instantly share code, notes, and snippets.

@faridfr
Created June 5, 2018 16:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faridfr/22f4449b08edbc51fc3b7f0df93bb269 to your computer and use it in GitHub Desktop.
Save faridfr/22f4449b08edbc51fc3b7f0df93bb269 to your computer and use it in GitHub Desktop.
preparing string for compare
<?php
function psfc ($string){
$string =
strtolower(str_replace(' ', '',convert_numbers_to_english(preg_replace('/\s+/', '', $string))));
return $string;
}
function convert_numbers_to_english($string) {
$persian = ['۰', '۱', '۲', '۳', '۴', '۵', '۶', '۷', '۸', '۹'];
$arabic = ['٩', '٨', '٧', '٦', '٥', '٤', '٣', '٢', '١','٠'];
$num = range(0, 9);
$convertedPersianNums = str_replace($persian, $num, $string);
$englishNumbersOnly = str_replace($arabic, $num, $convertedPersianNums);
return $englishNumbersOnly;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment