forked from petewarden/genderfromname
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
executable file
·77 lines (64 loc) · 1.63 KB
/
index.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?php
/**
* Test page for the GenderFromName module. If there's a 'name' URL parameter, it will use the module
* to guess the gender based on the first word in the name
* By Pete Warden <[email protected]>
* See http://petewarden.typepad.com/ for more details
*
*/
require_once ('genderfromname.php');
if (isset($_REQUEST['name'])) {
$name = urldecode($_REQUEST['name']);
} else {
$name = '';
}
?>
<html>
<head>
<title>Test page for the GenderFromName module</title>
</head>
<body>
<div style="padding:20px;">
<center>
<form method="GET" action="index.php">
Name: <input type="text" size="40" name="name" value="<?=$name?>"/>
</form>
</center>
</div>
<div>
<center>
<?php
if ($name!='') {
$DEBUG = 1;
$strictness = 9; // Set this to 1 or 2 for more restrictive matching
$nameparts = explode(' ', $name);
$firstname = $nameparts[0];
// get some name data
include('data/males.php');
include('data/females.php');
$result = GenderGuesser::init()
->setFirstName($firstname)
->setMaleFirstNames($Males)
->setFemaleFirstNames($Females)
->setSeverity($strictness)
->guess();
if (isset($result))
{
$gender = $result['gender'];
$confidence = $result['confidence'];
if ($gender==='f')
$gendername = 'female';
else
$gendername = 'male';
print "GenderFromName guesses that '$name' is $gendername, with confidence of $confidence (0 is most confident)";
}
else
{
print "GenderFromName couldn't make a good guess what $name's gender is";
}
}
?>
</center>
</div>
</body>
</html>