-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gender.php
58 lines (48 loc) · 1.46 KB
/
Gender.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace ArabyPHP\Gender;
class Gender
{
/**
* Check if Arabic word is feminine.
*
* @param string $str Arabic word you would like to check if it is
* feminine
*
* @return bool Return true if input Arabic word is feminine
*
*/
public function isFemale($str)
{
$female = false;
$words = explode(' ', $str);
$str = $words[0];
$str = str_replace(['أ', 'إ', 'آ'], 'ا', $str);
$last = mb_substr($str, -1, 1, 'UTF-8');
$beforeLast = mb_substr($str, -2, 1, 'UTF-8');
if ($last == 'ة' || $last == 'ه' || $last == 'ى' || $last == 'ا' || ($last == 'ء' && $beforeLast == 'ا')) {
$female = true;
} elseif (preg_match('/^[اإ].{2}ا.$/u', $str) || preg_match('/^[إا].ت.ا.+$/u', $str)) {
// الأسماء على وزن إفتعال و إفعال
$female = true;
} else {
// List of the most common irregular Arabic female names
$names = $this->getJsonData(__DIR__.'/data/female.json');
$names = array_map('trim', $names);
if (array_search($str, $names) > 0) {
$female = true;
}
}
return $female;
}
/**
* Check if Arabic word is note feminine.
*
* @param $str
*
* @return bool
*/
public function isMale($str)
{
return $this->isFemale($str);
}
}