homer.favenir Posted April 3, 2009 Share Posted April 3, 2009 hi, can anyone please help me with this... i think its very simple task but needs deep thinking... 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 More sharing options...
redarrow Posted April 3, 2009 Share Posted April 3, 2009 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; ?> Link to comment https://forums.phpfreaks.com/topic/152329-explode-address-cty-state-zc/#findComment-800025 Share on other sites More sharing options...
xtopolis Posted April 3, 2009 Share Posted April 3, 2009 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. Link to comment https://forums.phpfreaks.com/topic/152329-explode-address-cty-state-zc/#findComment-800040 Share on other sites More sharing options...
homer.favenir Posted April 3, 2009 Author Share Posted April 3, 2009 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 Link to comment https://forums.phpfreaks.com/topic/152329-explode-address-cty-state-zc/#findComment-800046 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.