Skip to content

Commit

Permalink
Added examples
Browse files Browse the repository at this point in the history
Added additional examples on how to use the classes.
  • Loading branch information
Ninble committed Sep 19, 2022
1 parent 1c09eff commit 7435008
Showing 1 changed file with 37 additions and 12 deletions.
49 changes: 37 additions & 12 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,57 @@
//Get your API key on https://parser.name/
$apiKey = "1bf857dfdabefb9a33cab34be438dbc2";

//This class holds all functionality you need.
require("src/NameParser/class.account.php");
//These classes hold all functionality.
require("src/NameParser/class.extract.php");
require("src/NameParser/class.generate.php");
require("src/NameParser/class.parse.php");
//require("src/NameParser/class.validate.php");
//require("src/NameParser/class.generate.php");

try {

//Initialize the class as a new instance.
//Initialize the class that parses names.
$name = new clsParseName($apiKey);

//Parse a complete name.
if ($name->fromCompleteName("Linus Benedict Torvalds")) {
print_r($name->gender()); //Returns "m"
print_r($name->gender().PHP_EOL); //Returns "m".
}

//Parse an email address.
if ($name->fromEmailAddress("linus.torvalds@protonmail.org")) {
print_r($name->salutation()); //Returns "Mr."
print_r($name->firstname()); //Returns "Linus"
print_r($name->lastname()); //Returns "Torvalds"
print_r($name->response()); //Returns "m"
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 "Ecexption: ".$e->getMessage();
echo "Exception: ".$e->getMessage();
}

?>

0 comments on commit 7435008

Please sign in to comment.