-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
59 lines (47 loc) · 1.88 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
<?php
//Get your API key on https://parser.name/
$apiKey = "";
//These classes hold all functionality.
require("src/NameParser/class.extract.php");
require("src/NameParser/class.generate.php");
require("src/NameParser/class.parse.php");
try {
//Initialize the class that parses names.
$name = new clsParseName($apiKey);
//Parse a complete name.
if ($name->fromCompleteName("Linus Benedict Torvalds")) {
print_r($name->gender().PHP_EOL); //Returns "m".
}
//Parse an email address.
if ($name->fromEmailAddress("linus.torvalds@protonmail.org")) {
print_r($name->salutation().PHP_EOL); //Returns "Mr.".
print_r($name->firstname().PHP_EOL); //Returns "Linus".
print_r($name->lastname().PHP_EOL); //Returns "Torvalds".
print_r($name->gender().PHP_EOL); //Returns "m".
}
//Validate a name.
if ($name->validate("random_mnbas")) {
var_dump($name->valid()); //Returns "bool(false)".
}
//Initialize the class that generates names.
$names = new clsGenerateNames($apiKey);
//Generate five random name.
if ($names->generate(5)){
foreach($names->list() as $name){
print_r($name.PHP_EOL); //Returns five random names.
$details = $names->details($name); //Returns all details we have on the generated name.
}
}
//Initialize the class that extracts names.
$names = new clsExtractNames($apiKey);
//Extract names from text.
if ($names->extract("Veteran quarterback Philip Rivers moved ahead of Matteo Federica on the NFL's all-time passing list.")) {
foreach($names->list() as $name){
print_r($name.PHP_EOL); //Returns "Philip Rivers" and "Matteo Federica".
$details = $names->details($name); //Returns all data we have on the extracted name.
}
}
} catch (exception $e) {
echo "Exception: ".$e->getMessage();
}
?>