RecogniContact/Web - International Address Parser Web Service - PHP demo
SOAP Methods
class ParsingResult
class VersionInfo
class LicenseInfo
class UsageStats
Exceptions
PHP demo
C# demo
Java demo

PHP demo


This code is a complete PHP demo project showing how to use RecogniContact/Web in a PHP project.

Please copy the source code to a text editor and save it as a file with the extension .php

NOTE! You will need a valid RecogniContact license to run this demo.
Before running the demo, please insert the license key to the source code where indicated.

NOTE! In order to run this project, the the SOAP extension must be activated in your PHP installation.

In Windows, you can do this by activating (un-commenting) the line
extension=php_soap.dll
in the PHP configuration file PHP.ini

In most Linux distributions, you can install the PHP SOAP extension by running
yum install php-soap

Web hosting products with pre-installed PHP usually have the SOAP extension installed. Please verify with you hosting provider.

Demo source code

<html>
<pre>
<?php

try
  {
                        
    //----------------------------------------------------------------
    // Set license key
    //----------------------------------------------------------------

    $LicenseKey='';  // <---REPLACE WITH YOUR LICENSE KEY!!!

    //----------------------------------------------------------------
    // Create SOAP Client
    //----------------------------------------------------------------

    $wsdl ='http://loquisoft.net/cgi-bin/RecogniContactWebService.exe/wsdl/IRecogniContactWebService';
    
    $RecogniContact = new SoapClient($wsdl);
      
      
    //----------------------------------------------------------------
    // Show License Information 
    //----------------------------------------------------------------
    
    print "\n";
    print "LICENSE INFORMATION \n";
    
    $LicenseInfo = $RecogniContact->GetLicenseInfo($LicenseKey);

      //license expiry date (as a string)
      //empty string = no time limit
    print "LicenseExpiryDateAsString= " . $LicenseInfo->LicenseExpiryDateAsString . "\n";

      //permitted total number of parsing operations 
      //0 = unlimited
    print "MaxParsings=               " . $LicenseInfo->MaxParsings . "\n";

      //permitted number of parsing operations per period of time
      //0 = unlimited
    print "MaxParsingsPerDay=         " . $LicenseInfo->MaxParsingsPerDay . "\n";
    print "MaxParsingsPerWeek=        " . $LicenseInfo->MaxParsingsPerWeek . "\n";
    print "MaxParsingsPerMonth=       " . $LicenseInfo->MaxParsingsPerMonth . "\n";
    print "MaxParsingsPerQuarter=     " . $LicenseInfo->MaxParsingsPerQuarter . "\n";
    print "MaxParsingsPerYear=        " . $LicenseInfo->MaxParsingsPerYear . "\n";
    
      //IP addresses allowed to call RecogniContact web service
      //Empty string = no limitation
    print "CallerIPRange=             " . $LicenseInfo->CallerIPRange . "\n";

      //licensed Parser countries 
      //Empty string = no limitation
    print "ParserCountries=           " . $LicenseInfo->ParserCountries . "\n";
    
      //user name associated with license key
    print "UserName=                  " . $LicenseInfo->UserName . "\n";

      //Additional info about license owner
    print "UserInfo=                  " . $LicenseInfo->UserInfo . "\n";
        
        //var_dump($LicenseInfo); 
        //print "\n";

                //----------------------------------------------------------------
    // Show Usage Statistics 
    //----------------------------------------------------------------

    print "\n";
    print "USAGE STATISTICS\n";
    
    $UsageStats = $RecogniContact->GetUsageStats($LicenseKey);
    
      //total number of completed parsing operations so far
    print "NumberParsings=            " . $UsageStats->NumberParsings . "\n";
    
      //number of completed parsing operations per period of time
    print "NumberParsingsToday=       " . $UsageStats->NumberParsingsToday . "\n";
    print "NumberParsingsThisWeek=    " . $UsageStats->NumberParsingsThisWeek. "\n";
    print "NumberParsingsThisMonth=   " . $UsageStats->NumberParsingsThisMonth. "\n";
    print "NumberParsingsThisQuarter= " . $UsageStats->NumberParsingsThisQuarter. "\n";
    print "NumberParsingsThisYear=    " . $UsageStats->NumberParsingsThisYear. "\n";

        //var_dump($UsageStats); 
        //print "\n";
    
                //----------------------------------------------------------------
    // Show Version Information for Parser and Parser Interface
    //----------------------------------------------------------------
    print "\n";
    print "VERSION INFORMATION\n";
    print 'GetParserVersionAsString()=   ' . $RecogniContact->GetParserVersionAsString() . "\n";
    print 'GetInterfaceVersionAsString()=' . $RecogniContact->GetInterfaceVersionAsString() . "\n";
    print "\n";

    
                //----------------------------------------------------------------
    // Call Parser 
    //----------------------------------------------------------------

    print "\n";
    print "CALL PARSER\n";

                
    $TextToParse="Dr. Walter W. Wagoner - Exhibition Manager\n" .
                "The Museum of Modern Art\n" .
                "Address: 11 West 53 Street, New York, NY 10019\n" .
                "Phone:   (212) 708-9400\n" .
                "Email:   info@moma.org\n" .
                "Web:     www.moma.org\n";


                
    print "Source text to parse:\n";
    print $TextToParse;
    print "\n\n";

    //NOTE!
    //  Parse() tries to interpret the entire text as an address/contact data string.
    //To SEARCH a text - such as CVs, resumes, web sites - for address and contact  
    //information and parse it, use 
    //  FindAndParse() 

    $ParsingResult = $RecogniContact->Parse($LicenseKey, $TextToParse);
    //$ParsingResult = $RecogniContact->FindAndParse($LicenseKey, $TextToParse);

                //----------------------------------------------------------------
    // Show Parsing Result
    //----------------------------------------------------------------

    print "\n";
    print "PARSING RESULT\n";

    print "Prefix=         " . $ParsingResult->Prefix . "\n";
    print "FirstName=      " . $ParsingResult->FirstName . "\n";
    print "MiddleName=     " . $ParsingResult->MiddleName  . "\n";
    print "LastName=       " . $ParsingResult->LastName . "\n";
    print "Suffix=         " . $ParsingResult->Suffix . "\n";
    print "Company=        " . $ParsingResult->Company . "\n";
    print "Company2=       " . $ParsingResult->Company2 . "\n";
    print "Position=       " . $ParsingResult->Position . "\n";
    print "StreetAddress1= " . $ParsingResult->StreetAddress1 . "\n";
    print "StreetAddress2= " . $ParsingResult->StreetAddress2 . "\n";
    print "PostboxAddress= " . $ParsingResult->PostboxAddress . "\n";
    print "PostboxPostCode=" . $ParsingResult->PostboxPostCode . "\n"; 
    print "PostCode=       " . $ParsingResult->PostCode . "\n"; 
    print "PlaceName=      " . $ParsingResult->PlaceName . "\n"; 
    print "Province=       " . $ParsingResult->Province . "\n"; 
    print "Country=        " . $ParsingResult->Country . "\n"; 
    print "Phone1=         " . $ParsingResult->Phone1 . "\n";
    print "Phone2=         " . $ParsingResult->Phone2 . "\n"; 
    print "Mobile=         " . $ParsingResult->Mobile . "\n"; 
    print "Fax=            " . $ParsingResult->Fax . "\n"; 
    print "Email=          " . $ParsingResult->Email . "\n"; 
    print "Url=            " . $ParsingResult->Url . "\n"; 
    print "Gender=         " . $ParsingResult->Gender . "\n"; 
    print "CountryIsoCode= " . $ParsingResult->CountryIsoCode . "\n"; 
    
    print "\n";

    //output unrecognized items
                if ($ParsingResult->UnrecognizedItems != '') { 
      $unrecognized_items_array = split('\|', $ParsingResult->UnrecognizedItems);
      for ($i=0; $i < count($unrecognized_items_array); $i++) {
        print "Unrecognized item " . $i . "= " . $unrecognized_items_array[$i] . "\n";           
      }
    }
   
  }



catch(Exception $e)
  {     
        
  //----------------------------------------------------------------
  // Exception handling
  //----------------------------------------------------------------

  $errormessage=$e->getMessage();
  echo 'Error: ' .$errormessage . "\n";

    //dump exception details:
    //var_dump($e);
  
 
  //----------------------------------------------------------------
  // Get RecogniContact Error Code;
  // If required, add further exception handling code below
  //----------------------------------------------------------------

  $errorcode=GetRecogniContactErrorCode($errormessage);
  
  switch ($errorcode) {
         
        case 1: //Invalid license key
                //-----------------------------
                //The license key provided is invalid
                                         
        case 2: //Invalid request IP
                //-----------------------------
                      //The license does not allow web service requests from the current IP address
                                        
        case 10://License has expired
                //-----------------------------
                //A time limit was set for your license and this limit was reached
                
        case 20://Parsing quota exceeded
                //-----------------------------
                //A maximum number of permitted parsing operations is set for your license 
                //and this limit was exceeded. 
                                
                //The quota can be set per day/week/month/quarter/year or as a total limit
        
        case 30://Unlicensed country
                //-----------------------------
                            //The country of the specified address or contact data is 
                            //not included in your license 
        
        case 99://Internal RecogniContact server error
                //------------------------------------
                //An unexprected error occured on the RecogniContact server.
                //Please contact LoquiSoft for assistance.
                

        case 0: //Other error
                //-----------------------------
                //Exception was not created by RecogniContact
  }   
}  
  
  
function GetRecogniContactErrorCode($errormessage) {   
        //extracts the error code from a RecogniContact error message, which has the format
        //  RecogniContact Error NN: Error description
        //where NN is the error code 
                
  if (preg_match("/RecogniContact Error (\d+)/", $errormessage, $matches)) {
        return $matches[1];
  } else {
        return 0;
  }
}
  
?>

</pre>
</html>