[RESOLVED] explode help
Results 1 to 6 of 6

Thread: [RESOLVED] explode help

  1. #1
    Hockey Stats Man
    Join Date
    Nov 2006
    Location
    FSJ, BC, Canada
    Posts
    297

    resolved [RESOLVED] explode help

    my site i get stats provided to me in cvs format which i then can put into my database via a .cvs importer but I have noticed an issue with my coding in where it explodes the Birth City.

    Ex.. Canadian and United States players it will show the
    City, State/Province, Country

    where all other countries show only
    City, Country

    When I first made the script i only needed City, Country so thats all I included now I need to make it so when its importing it can tell the difference.

    here is the code that explodes the Birth City

    Code:
    $birthplace = str_replace('Birth place:', '', $section);
    					$temp = explode(',', $birthplace);
    					$birthcity = trim($temp[0]);
    					$country = trim($temp[1]);
    mike carter

  2. #2
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,419
    Not sure what you're asking, but it sounds like you just need to count() the number of pieces you get once the string has been explode()'d in order to determine which pieces of information you have (based on the two formats you described, anyway).

  3. #3
    Hockey Stats Man
    Join Date
    Nov 2006
    Location
    FSJ, BC, Canada
    Posts
    297
    So this file i get it has some players birth city listed like city, country

    this is where i seperate in my code above

    but now the cvs file that is sent to me has 2 different ways to display the birth city
    #1 city, country (this is the way i have done)
    #2 city, state, country (when i do this it leaves out the country all together cause of the way my code is and uses state as the country.

    what i need to do is find a way to explode correctly so that say
    #1 city, country (will explode the way it does now)
    #2 city, state, country (where city, state = $birthcity and country = $country)

    i
    mike carter

  4. #4
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,419
    So did you try what I suggested above?

  5. #5
    Hockey Stats Man
    Join Date
    Nov 2006
    Location
    FSJ, BC, Canada
    Posts
    297
    i am working on it right now.. will let you know how i make out
    mike carter

  6. #6
    Hockey Stats Man
    Join Date
    Nov 2006
    Location
    FSJ, BC, Canada
    Posts
    297
    i know this is alittle old but i did figure it out so i thought id post my code here for people that may need an example if they have a similar issue

    thanks to bradgrafelman for pointing me in the right direction

    Code:
    this is just the code i used for testing
    					$birthplace = 'Sydenham, Ontario, Canada';
    
    					$temp = explode(',', $birthplace);
                                            $count = count($temp); 
    if ($count == 3) {
    					$birthcity1 = trim($temp[0]);
    					$birthcity2 = trim($temp[1]);
                                            $birthcity = $birthcity1.', '. $birthcity2;
    					$country = trim($temp[2]);
                                                           } else {
    					$birthcity = trim($temp[0]);
    					$country = trim($temp[1]);
                                                           }
    
    echo $birthcity;
    echo $country;
    mike carter

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •