PHP code example of popphp / pop-parser

1. Go to this page and download the library: Download popphp/pop-parser library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

popphp / pop-parser example snippets


use Pop\Parser\Address\AddressParser;

$parser = new AddressParser();
$result = $parser->parse('123 Main St Apt 4B, Springfield, IL 62704');

$result->getStreetNumber(); // '123'
$result->getStreetName();   // 'Main'
$result->getRouteType();    // 'St'
$result->getUnit();         // 'Apt 4B'
$result->getCity();         // 'Springfield'
$result->getStateCode();    // 'IL'
$result->getStateName();    // 'Illinois'
$result->getPostalCode();   // '62704'
$result->getCountry();      // 'US'

$parser = new AddressParser('123 Main St, Springfield, IL 62704');
$result = $parser->parse();

$parser = new AddressParser();
$result = $parser->parse('456 N Elm Street, Chicago, IL 60601');

$result->getDirection();          // 'N'
$result->getStreetName();         // 'N Elm'
$result->getStreetName(false);    // 'Elm'
$result->getRouteType();          // 'Street'

$parser = new AddressParser();
$result = $parser->parse('PO Box 1234, Springfield, IL 62704');

$result->isPoBox();       // true
$result->getStreetName(); // 'PO Box 1234'
$result->getCity();       // 'Springfield'

$result->getFullAddress();
// '123 Main St, Apt 4B, Springfield, IL 62704'

// Options: delimiter, whether to use the state code vs. full state name, whether to 'streetName' => 'Main', 'routeType' => 'St',
//     'direction' => null, 'unit' => 'Apt 4B', 'city' => 'Springfield',
//     'postalCode' => '62704', 'zip4' => null, 'stateName' => 'Illinois',
//     'stateCode' => 'IL', 'country' => 'US', 'confidence' => 1.0,
// ]

(string) $result; // same as getFullAddress()

$result->getConfidence();     // 1.0
$result->isConfident();       // true (default threshold: 0.7)
$result->isConfident(0.9);    // pass a stricter threshold if you need one

use Pop\Parser\Name\NameParser;

$parser = new NameParser();
$result = $parser->parse('Dr. John Michael Smith Jr.');

$result->getSalutation(); // 'Dr.'
$result->getFirstname();  // 'John'
$result->getMiddlename(); // 'Michael'
$result->getLastname();   // 'Smith'
$result->getSuffix();     // 'Jr'
$result->getFullName();   // 'John Michael Smith'
(string) $result;         // 'Dr. John Michael Smith Jr'

$parser = new NameParser('John Smith');
$result = $parser->parse();

$parser = new NameParser();
$result = $parser->parse('Smith, John Michael, Jr');

$result->getFirstname();  // 'John'
$result->getMiddlename(); // 'Michael'
$result->getLastname();   // 'Smith'
$result->getSuffix();     // 'Jr'

$parser = new NameParser();
$result = $parser->parse('Ludwig van Beethoven');

$result->getLastnamePrefix(); // 'van'
$result->getLastname();       // 'Beethoven'
$result->getFullName();       // 'Ludwig van Beethoven'

$parser = new NameParser();
$result = $parser->parse('J.R. "Bob" Smith');

$result->getFirstname();    // 'J'
$result->getInitials();     // 'R'
$result->getNickname();     // 'Bob'
$result->getNickname(true); // '(Bob)'
$result->getLastname();     // 'Smith'

$parser = new NameParser();
$result = $parser->parse('Anthony Von Fange III, PhD');

$result->getSuffix();      // 'III'
$result->getCredentials(); // 'PhD'

$result->getGivenName(); // firstname + initials + middlename, whichever are present
$result->getFullName();  // given name + lastname prefix + lastname

$result->toArray();
// [
//     'salutation' => null, 'firstname' => 'John', 'initials' => null,
//     'middlename' => 'Michael', 'nickname' => null, 'lastnamePrefix' => null,
//     'lastname' => 'Smith', 'suffix' => 'Jr', 'credentials' => null, 'confidence' => 1.0,
// ]

(string) $result; // salutation + given name + nickname + lastname prefix + lastname + suffix + credentials

$result->getConfidence();  // 1.0
$result->isConfident();    // true (default threshold: 0.7)