#2 european address format is "postcode city"

Unstable (example)
open-works-for-me
nobody
None
5
2011-12-21
2011-12-21
Markus Neubauer
No

In the structuredPostalAddress loop i've tried the following code to improve the display format for europen country addresses:
After $address['country'] = (string) $a->country; i added:

// start guess european "postcode city" address format
if ( empty($address['postcode']) and empty($address['city']) ) {
$gadrpart = explode( "\n", $a->street );
if ( count($gadrpart) < 2 ) { // try blanks instead
$gadrpart = explode( ' ', $a->street );
if ( count($gadrpart) > 2 ) {
$i = 0;
$b = array();
foreach ( $gadrpart as $gadrpart2 ) {
if ( is_numeric($gadrpart2) ) { // assume numeric ~ house or zip
$b[$i] = ' ' . $gadrpart2;
$i++;
} else {
$b[$i] = $gadrpart2;
}
}
$gadrpart = $b;
}
}

if ( !empty($gadrpart[0]) ) $address['street'] = $gadrpart[0];
if ( !empty($gadrpart[1]) ) $address['city'] = $gadrpart[1];
if ( !empty($gadrpart[2]) ) $address['country'] = $gadrpart[2];
if ( !empty($address['city']) ) {
$gadrpart = explode( " ", $address['city'] );

foreach ( $gadrpart as $gadrpart2 ) {
if ( is_numeric($gadrpart2) ) {
$address['postcode'] = $gadrpart2;
$address['city'] = str_replace($address['postcode'], "", $address['city']);
$address['city'] = preg_replace("/^ | $/", "", $address['city']);
break;
}
}
}
}
// end guess european "postcode city" address format

// if we have all address components, use them, otherwise let vcard figure it out from the formatted address
// MN disabled region, cause not often used in EU:
// if( !empty($address['city']) && !empty($address['postcode']) && !empty($address['region']) && !empty($address['street']) ){
if( !empty($address['city']) && !empty($address['postcode']) && !empty($address['street']) ){

Maybe a switch in config.inc.php would be a good idea to invoke/exclude the code execution?

hth Markus

Discussion

    • status: open --> open-works-for-me
     
  • more efficient than:
    $address['city'] = preg_replace("/^ | $/", "", $address['city']);
    is
    $address['city'] = trim($address['city']);