Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Branch: master
Fetching contributors…

Cannot retrieve contributors at this time

73 lines (66 sloc) 2.265 kB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>HumanNameParser demo</title>
<style type="text/css">{margin-bottom: 1em;}
h2{font-size:1em;padding:0;margin:0;color:#fff;width:50%} h2 {background-color: green;} h2 {background-color: red;}{color:red;}{color:green;}
<h1>HumanNameParser test page</h1>
<div id="intro">
This page uses the test names included in testNames.txt. See
<a href="./README"></a> file included for more details. Names
are listed as:
<li>Leading initial</li>
<li>First name</li>
<li>Middle names</li>
<li>Last names (surnames)</li>
<li>Suffixes (like "Jr.")</li>
* Page to test performance of the parser
require_once './init.php';
function testEqual($expected, $actual)
if ($expected === '') $expected = "[empty]";
if ($actual === '') $actual = "[empty]";
if ($actual === $expected) {
$ret = "<span class='win'>$expected = $actual</span>";
else {
$ret = "<span class='fail'>$expected$actual</span>";
return $ret;
$handle = fopen('./Tests/testNames.txt', 'r');
while ($nameArr = fgetcsv($handle, 1000, "|")){
$parser = new HumanNameParser_Parser($nameArr[0]);
// check to see if the parser got each name-part correct
$ret = testEqual($nameArr[1], $parser->getleadingInit() );
$ret .= testEqual($nameArr[2], $parser->getFirst() );
$ret .= testEqual($nameArr[3], $parser->getNicknames() );
$ret .= testEqual($nameArr[4], $parser->getMiddle() );
$ret .= testEqual($nameArr[5], $parser->getLast() );
$ret .= testEqual($nameArr[6], $parser->getSuffix() );
$divClass = (strpos($ret, "class='fail'")) ? "fail" : "win"; // a hacky way to do this
echo "<div class='name $divClass'><h2 class='test-name'>{$nameArr[0]}</h2>$ret</div>";
Jump to Line
Something went wrong with that request. Please try again.