Help parsing addresses (any ideas?)

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Sugapablo

    Help parsing addresses (any ideas?)

    I need some PHP code to do the following, any ideas? There are so many
    things to take into consideration, but places like mapquest seem to be
    able to handle this ok.

    I would like this to be written as a function
    parseaddress($a ddress)

    Given a variable $address parse it out into the following variables:

    $housenumber
    $streetname
    $type
    $prefix
    $postfix

    Examples:

    $address = "123 N Main Street"
    would return:
    $housenumber = "123"
    $streename = "Main"
    $type = "Street"
    $prefix = "North"
    $postfix = ""

    $address = "123 Main Street N"
    would return:
    $housenumber = "123"
    $streename = "Main"
    $type = "Street"
    $prefix = ""
    $postfix = "North"

    $address = "123 Main Street North"
    would return:
    $housenumber = "123"
    $streename = "Main"
    $type = "Street"
    $prefix = ""
    $postfix = "North"

    $address = "123 Main Rd"
    would return:
    $housenumber = "123"
    $streename = "Main"
    $type = "Road"
    $prefix = ""
    $postfix = ""

    $address = "123 Arlington Centre Blvd."
    would return:
    $housenumber = "123"
    $streename = "Arlington Centre"
    $type = "Boulevard"
    $prefix = ""
    $postfix = ""



    $type could contain the following values:
    Road
    Street
    Place
    Court
    Lane
    Boulevard
    (more types?)
    (each type may be abreviated ie "Rd","St"," pl" etc)

    $prefix or $postfix could contain the following values:
    North
    South
    East
    West
    (each could be abreviated ie "N","S" etc)


    --
    [ Sugapablo ]
    [ http://www.sugapablo.com <--music ]
    [ http://www.sugapablo.net <--personal ]
    [ sugapablo@12jab ber.com <--jabber IM ]
  • John Wellesz

    #2
    Re: Help parsing addresses (any ideas?)

    On 06 avr. 2004, Sir Sugapablo <russREMOVE@sug apablo.com> claimed in
    news:slrnc7543l .l99.russREMOVE @dell.sugapablo .net:
    [color=blue]
    > I need some PHP code to do the following, any ideas? There are so many
    > things to take into consideration, but places like mapquest seem to be
    > able to handle this ok.
    >
    > I would like this to be written as a function
    > parseaddress($a ddress)[/color]


    Well it's time for you to learn to use regular expressions... It's
    difficult at first but then you'll think you should had learn them earlier
    :)

    here is the address to start learning:



    To make what you want you'll need the function preg_match().


    Happy learning!

    John

    Comment

    Working...