Script to convert full country name to 2 letter format (ISO 3166-1)

 

Results 1 to 5 of 5
Hi, I need a script to convert the full country names in a file to ...
  1. #1
    hellnation's Avatar
    hellnation is offline Regular Member
    Join Date
    Feb 2013
    Location
    Quebec, Canada
    Age
    38
    Posts
    277
    Thanks
    104
    Thanked 59 Times in 43 Posts

    Default Script to convert full country name to 2 letter format (ISO 3166-1)

    Hi,

    I need a script to convert the full country names in a file to the 2 letter format.

    I looked around and didn't find anything, looks like the best way is to make a php script that reads a conversion table and then convert the data.

    However, I couldn't find any examples, how can I do this?

    Here is a library that can be used to do this:

    https://github.com/johannesl/Internationalization

    I'm guessing a lot of others have faced the same issue before, seems like a common problem.

    Thanks!




  2. #2
    hellnation's Avatar
    hellnation is offline Regular Member
    Join Date
    Feb 2013
    Location
    Quebec, Canada
    Age
    38
    Posts
    277
    Thanks
    104
    Thanked 59 Times in 43 Posts

    Default Re: Script to convert full country name to 2 letter format (ISO 3166-1)

    or anyone know the best place to ask for this?

  3. #3
    garthor's Avatar
    garthor is offline Newbies
    Join Date
    Mar 2013
    Posts
    48
    Thanks
    10
    Thanked 12 Times in 9 Posts

    Default Re: Script to convert full country name to 2 letter format (ISO 3166-1)

    I believe it's pretty much straightforward. It even comes with a PHP example :


    https://github.com/johannesl/Interna...er/example.php


    All You need to do is simply download these two files :


    https://github.com/johannesl/Interna...tryaliases.php
    https://github.com/johannesl/Interna...untrynames.php


    Include them both at the top of the top of the php script you will use this code on.
    Then, you will be able to use a function called : string2countrycode.


    Code:
    $code = string2countrycode('Sweden');

    Basically, You pass the country name with the function and it will return the two letter format back as you'd like.
    It will be store in the code variable in this case. If you echo it, the output would be : "SE" as that's Sweden 2 letter format.

  4. #4
    sshaw is offline Newbies
    Join Date
    Jun 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Script to convert full country name to 2 letter format (ISO 3166-1)

    Hi, I have written a Ruby library and utility program that will convert to/from a variety of country names and codes. The program will convert data from a database, XML file or directory of XMLs, and, at some point, CSV.

    It can be found at (note that this forum wont allow me to post links, so I had to improvise): it's on GitHub at /sshaw/normalize_country

    You'll have to download it from github as the version on rubygems (public repository of Ruby libraries) does not include the utility program.
    Also note that I haven't finished the CSV option.

    I only used the library so I'd appreciate any feedback on the command line program.

    Be sure to backup your data before using this. It is a work in progress.

  5. #5
    sshaw is offline Newbies
    Join Date
    Jun 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Script to convert full country name to 2 letter format (ISO 3166-1)

    Hellnation, I can't send private messages until I have "15 posts". I will take a look at the permission issue. It might be a problem with the script as I have never ran it on Windows.

    What's the format of your XML file?


Similar Threads

  1. Replies: 9
    Last Post: 12-24-2013, 08:01 AM
  2. Replies: 3
    Last Post: 07-21-2010, 08:06 AM
  3. Replies: 4
    Last Post: 01-30-2009, 08:34 PM

Bookmarks

Posting Permissions

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





BlackHatWorld on Twitter BlackHatWorld on FaceBook


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112