Jump to content

explode address, cty, state, zc


homer.favenir

Recommended Posts

hi,

can anyone please help me with this...

i think its very simple task but needs deep thinking... ;D

anyways

here's the situation

 

i have an address and i want to split them into Address, City, State, ZC

20 South Park Avenue Suite A, Apopka, FL 11111

but the road block is this address

12301 Lake Underhill Road, Suite 104, Orlando, FL 33333

exploding it by comma is applicable to the first address

but on second address i think the "Suite 104" should come with the address

 

and also this address (typo error)

430 N Mills Avenue, # 3,, Orlando, FL 22222

it has 2 commas

 

anyone has great ideas?

 

thanks man...

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/152329-explode-address-cty-state-zc/
Share on other sites

your need to work on this but it a clue sorry i am tired.

 

<?php


$test="430 N Mills Avenue, # 3,, Orlando, FL 22222";

if(strstr($test,',,')){
$test1=str_replace(',,',',',$test);
$res=explode(',',$test1);
$value="ADDRESS: {$res[0]} <br> CITY: {$res[1]} <br> STATE: {$res[2]}";
}else{
$res=explode(',',$test);
$value= "ADDRESS: {$res[0]} <br> CITY: {$res[1]} <br> STATE: {$res[2]}";
}


echo $value;
?>

If you can semi guarantee the order, work backwards through the string.

 

Match 5 numbers

2 Capital letters

1-2 words? (unless a city has more??)

and then everything else

 

Ultimately if it's user input that they are entering freehand, it will be error prone.  An option is to supply them with limited input segments/options to reduce the number of errors, that is, if the input is under your control.

but we only have the whole files, and we dont have the control to prevent the errors.

@redarrow is correct about the double comma, just search for double comma and replace it with single,

the only problem is

12301 Lake Underhill Road, Suite 104, Orlando, FL 33333

 

Suite 104 should come with the address but it has comma

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.