|
|
|
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
{
$LicenseKey=''; $wsdl ='http://loquisoft.net/cgi-bin/RecogniContactWebService.exe/wsdl/IRecogniContactWebService';
$RecogniContact = new SoapClient($wsdl);
print "\n";
print "LICENSE INFORMATION \n";
$LicenseInfo = $RecogniContact->GetLicenseInfo($LicenseKey);
print "LicenseExpiryDateAsString= " . $LicenseInfo->LicenseExpiryDateAsString . "\n";
print "MaxParsings= " . $LicenseInfo->MaxParsings . "\n";
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";
print "CallerIPRange= " . $LicenseInfo->CallerIPRange . "\n";
print "ParserCountries= " . $LicenseInfo->ParserCountries . "\n";
print "UserName= " . $LicenseInfo->UserName . "\n";
print "UserInfo= " . $LicenseInfo->UserInfo . "\n";
print "\n";
print "USAGE STATISTICS\n";
$UsageStats = $RecogniContact->GetUsageStats($LicenseKey);
print "NumberParsings= " . $UsageStats->NumberParsings . "\n";
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";
print "\n";
print "VERSION INFORMATION\n";
print 'GetParserVersionAsString()= ' . $RecogniContact->GetParserVersionAsString() . "\n";
print 'GetInterfaceVersionAsString()=' . $RecogniContact->GetInterfaceVersionAsString() . "\n";
print "\n";
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";
$ParsingResult = $RecogniContact->Parse($LicenseKey, $TextToParse);
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";
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)
{
$errormessage=$e->getMessage();
echo 'Error: ' .$errormessage . "\n";
$errorcode=GetRecogniContactErrorCode($errormessage);
switch ($errorcode) {
case 1:
case 2:
case 10:
case 20:
case 30:
case 99:
case 0: }
}
function GetRecogniContactErrorCode($errormessage) {
if (preg_match("/RecogniContact Error (\d+)/", $errormessage, $matches)) {
return $matches[1];
} else {
return 0;
}
}
?>
</pre>
</html>
|