PHP Classes
elePHPant
Icontem

File: exampleUsage.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of G. Miernicki  >  Name Parser  >  exampleUsage.php  >  Download  
File: exampleUsage.php
Role: Example script
Content type: text/plain
Description: example class usage
Class: Name Parser
Parse a person full name to retrieve its parts
Author: By
Last change: new version 1.1
Date: 6 years ago
Size: 1,200 bytes
 

Contents

Class file image Download
<?php
require_once('nameParser.php');
$names = file('exampleNames.txt');
$np = new nameParser();
?><table><tr><td><b>Full Name</b></td><td><b>Title</b></td><td><b>First</b></td><td><b>Middle</b></td><td><b>Last</b></td><td><b>Suffix</b></td></tr>
<style type="text/css">
* { padding: 0px; margin: 0px;}
body { margin: 10px; }
td { padding: 5px; background-color: #fff; font-size: 14px; border: 1px solid #ccc;}
.odd { background-color: #eee; }
</style><?

$eo
= 1;
foreach(
$names as $name) {
    if (
$eo == 1 )
       
$eoc = "odd";
    else
       
$eoc = "";
   
$name = trim($name);
    if(!
$name) { continue; }
   
$np->setFullName($name);
   
$np->parse();
    if( !
$np->getNotParseable() ) {
        echo
"<tr><td class=\"".$eoc."\"><i>".$name."</i></td><td class=\"".$eoc."\">".$np->getTitle()."&nbsp;</td><td class=\"".$eoc."\">";
        echo
$np->getFirstName()."&nbsp;</td><td class=\"".$eoc."\">".$np->getMiddleName()."&nbsp;</td><td class=\"".$eoc."\">";
        echo
$np->getLastName()."&nbsp;</td><td class=\"".$eoc."\">".$np->getSuffix()."&nbsp;</td></tr>";
    } else {
        echo
"<tr><td class=\"".$eoc."\"><i>".$name."</i></td><td class=\"".$eoc."\" colspan=5><center><b>Not parseable.</b></td>\n";
    }
   
$eo++;
    if (
$eo == 2 ) $eo = 0;
}