Domanda

I have an HTML form that takes an input shipping address in parts (street address, city, state/province, postal code, and country). This form is then processed with PHP.

I'd like to convert this address into the correct format for the destination country. Are there any libraries or external services that I could use to do this conversion in PHP? If not, could I do it with Perl or a similar language?

È stato utile?

Soluzione 3

I've thought about this problem and I've decided that a file/database with address templates listed for each country is the best solution for me.

However, I'm certain that the other solutions given would work as well.

Altri suggerimenti

Never used it but Geo::PostalAddress is a good starting point. Useful links to regulations if nothing else.

Note that various shipping companies (Fedex, DHL etc) have their own rules for address format.

In Perl you can use Class::Phrasebook. Using it is very easy.

use Class::Phrasebook;
my $pb = new Class::Phrasebook($log, "test.xml");
$pb->load("NL"); # using Dutch as the language
$phrase = $pb->get("ADDRESS", 
                   { street => "Chaim Levanon",
                     number => 88,
                     city   => "Tel Aviv" } );

Now in your case the shipping address will be dynamic (which will be provided by the user) so you'll have to do some more work. You can create a XML file, add dictionaries for all the countries, add phrases (street address, city, state/province, postal code) in each dictionary. Write country specific data in each phrase like "Street address: $street" for English dictionary, "adresse: $street" for French dictionary etc. And then access the dictionary according to the user's country.

More information at CPAN.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top