Jump to content

James_S

New Members
  • Posts

    6
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

James_S's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Reasons why i'm doing this: 1. Emailing customers and ask to update is not an option. Maybe 10% will do it? 95% are one-time-customers - i wouldn't bother my self if i got such email - at least not until next time i shop there. And i really don't like emailing customers without good reasons (such email is close to what i call spam: emails you delete pretty instantly). But of course - next time i will email my customers, i will ask them to ALSO double check their addresses. 2. It's not a dissaster if the columns for address, zip or city are not perfect. The fields are not related to other tables with possible values (for instance a table of all existing zips) that needs to be matched. So no matter what i do, there will always be errors in the database, for instance because of typos in address users enter. 3. It's better to have 10% fields "not perfect" (and 90% perfect), than leaving everything completely out? 4. No, i will not double check the results, because of reason #2. :) I will do a try on the whole database afterwords, and do a quick scan over the results to see if i find any obvious faults. My guess is that at least 90% will be perfect. I've spent approx 2 hours on this project now, and i'm pretty sure that i would spend at least 100 hours to do this manually!
  2. Of course, the new database is done properly, and form have all fields, and they are properly validated before insert. I just want to transfer the old data to the new database. I have made a fairly good solution now: [code] <?php $address = "Thestreet 123 ,    3131 MYPLACE,COUNTRY"; //formatting messed up on purpose $cutLinefeeds = str_replace ( "\r\n", "", $address); $cutCommas = str_replace ( ",", " ", $cutLinefeeds); $cutSpaces = preg_replace('/\s\s+/', ' ', $cutCommas); preg_match('/[0-9][0-9][0-9][0-9]/i',$cutSpaces, $zip); $theZip = $zip[0]; if(!empty($theZip)) { $adressArray = explode(" ", $cutSpaces); $index = array_search($theZip, $adressArray); $city = $adressArray[$index+1]; $streetArray = array_slice($adressArray, 0, $index); $street = trim(implode(" ", $streetArray)); } else $street = $cutSpaces; echo "Street: $street<br>"; echo "Zip: $theZip<br>"; echo "City: $city<br>"; ?>[/code] Comments: - First i'm removing linefeeds and commas, so that every part have only a space between. - I assume that city will always come right after the zip. - I assume that if theres anything after city, it'is garbage. Usually theres nothing, but theres something it's always(?) country. Since all my customers are from same country, I don't need it. The most obvious bug i find now, is that if the street address also contains 4 digits, it will assume that is the zip. Does anyone have any other suggestions/improvements? Thanks!
  3. I guess you are assuming that the formating will always be the same there. Unfortunately, it is not... Sometimes the entire field will be empty, sometimes normal address without zip/country, sometimes even more details etc. I'm pretty sure that the only way to be sure that there is a zip code in the string, is to actually search for 4 digits. Thanks for all reaplies though. Fast responses here  :o
  4. I'm not sure i want to do that since it's my customers real addresses... But the content shouldn't matter the function works like i wrote in words: - Search the string for a 4-digit number and "cut" this and save to $zip instead - If the 4 digit zip was found, the next word is for sure "place", so this should also be cut and saved to $place. If zip was not found, don't do this. (- trim the string, and replace linefeeds with commas.)
  5. [quote author=redarrow link=topic=106443.msg425732#msg425732 date=1157086534] hard code it. blue fingers. [/quote] I think you misunderstand. I'm not trying to fix user input when it's being posted - then i would of course have separated these fields on the form instead. I already have 10 000 records, that i need to convert. So i need to create a function, so that i can loop through all records and apply it.
  6. Long time ago when i created my first database, i thought it was smart to store address, zip code, and city as one string in one DB-field. Now i have created a new database and splitted these into seperate fields. But i would really want to transfer the old data into the new database. Does anyone have a suggestion how i would achieve this: //current - note that it may contain line feeds, or commas. $address = "Thestreet 123 3131 MYPLACE COUNTRY"; //wanted $address = "Thestreet 123, COUNTRY" (for the ease, i can live with the country thing still being there) $zip = "3131" $place = "MYPLACE" In words: - Search for a 4-digit number and "cut" this and save to $zip instead - If zip is found, the next word is "place", so this should also be cut and saved to $place (- trim the string, and replace linefeeds with commas.) Note: The original address string varies a lot, since users entered this by them selves. So it's not always the same format, thus making it harder to solve... If someone wants to help me, i would be really thankful.
×
×
  • 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.