예제 #1
0
 public static function parse(\SimpleXMLElement $xml)
 {
     $addresses = array();
     foreach ($xml->address as $element) {
         $addresses[] = AddressParser::parse($element);
     }
     return $addresses;
 }
예제 #2
0
"><br />
		City length: <input type="input" name="city_length" value="<?php 
echo AddressParser::$city_length;
?>
"><br />
		<input type="hidden" name="action" value="PARSE" />
		<input type="submit" value="Parse" />
	</form>
	<br />
<?php 
if (isset($_POST['action']) && $_POST['action'] == 'PARSE' && !empty($addresses)) {
    //and there is something to parse ;-)
    echo '<table border="1" cellspacing="0" cellpadding="3" width="100%">' . '<tr><th>ID</th><th>STREET</th><th>POSTAL CODE</th><th>CITY</th><th width="200">Original text</th></tr>' . "\n";
    $lines = explode("\n", $addresses);
    $i = 0;
    foreach ($lines as $line) {
        $i++;
        if (empty($line) || trim($line) == '') {
            continue;
        }
        $parsed = AddressParser::parseAddress(rtrim($line, "\r\n"));
        echo '<tr><td>' . $i . '&nbsp;</td><td>' . safetd($parsed['CROPPED_STREET']) . '</td><td>' . safetd($parsed['POSTAL_CODE']) . '</td><td>' . safetd($parsed['CROPPED_CITY']) . '</td><td>' . safetd(rtrim($line, "\r\n")) . "</td></tr>\n";
    }
    echo "</table>\n";
}
?>
	<br />
	<hr />
	2009(c) by Seba ;-)
</body>
</html>
 static function setTrimAdditionalChars($value)
 {
     self::$trim_additional_chars = $value;
     self::$trim_chars = self::$important_separator_chars . self::$trim_additional_chars;
 }
예제 #4
0
 * phone number as.
 */
switch (urldecode($_REQUEST['mode'])) {
    case 'contact':
        $mode = ADDRESSPARSER_MODE_CONTACT;
        break;
    case 'company':
        $mode = ADDRESSPARSER_MODE_COMPANY;
        break;
    default:
    case 'person':
        $mode = ADDRESSPARSER_MODE_PERSON;
        break;
}
/* Instantiate a new AddressParser */
$addressParser = new AddressParser();
/* Feed the AddressParser a the address block from POST data and parse
 * the address.
 */
$addressBlock = urldecode($_REQUEST['addressBlock']);
$addressParser->parse($addressBlock, $mode);
/* Get the parsed address as an associative array. */
$parsedAddressArray = $addressParser->getAddressArray();
$phoneNumbers = $parsedAddressArray['phoneNumbers'];
/* Fetch individual phone numbers. */
$homePhoneRow = ResultSetUtility::findRowByColumnValue($phoneNumbers, 'type', 'home');
$workPhoneRow = ResultSetUtility::findRowByColumnValue($phoneNumbers, 'type', 'work');
$cellPhoneRow = ResultSetUtility::findRowByColumnValue($phoneNumbers, 'type', 'cell');
$faxRow = ResultSetUtility::findRowByColumnValue($phoneNumbers, 'type', 'fax');
if ($homePhoneRow !== false) {
    $homePhone = $phoneNumbers[$homePhoneRow]['number'];