Download the PHP package jabarihunt/country-codes without Composer

On this page you can find all versions of the php package jabarihunt/country-codes. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package country-codes

Country Code Class

This is a simple class used to get country codes and/or names. Normally this is something that would be stored and accessed from a database. However, this class will come in handy in situations where you...

  1. Are running your application someplace without access to a database
  2. Don't have proper permissions to add tables to a database
  3. Outside of a countries table, your application doesn't need a database

Requires PHP 7.0+ (due to type definitions)

INSTALLING

Via Composer

Run the following command in the same directory as your composer.json file:

composer require jabarihunt/country-codes

Via Github

  1. Clone this repository into a working directory: git clone [email protected]:jabarihunt/country-codes .

  2. Include the CountryCodes class in your project...

...or if using an auto-loader...

USAGE

Available Methods

There are two static methods publicly available in the class...

NOTE: The countries data is hard coded into the class as an array. However, the optional parameter ($useAPI) will spawn an HTTP request to the REST Countries API to retrieve live data. It's rare that countries change, but it does happen!

Additionally, there are five publicly available constants that represent class data types:

Retrieving Data For A Single Country

Suppose we have a country name, Haiti for example, and we want the 3 letter country code. We will use the get() method by passing it the type of value (country name in this case) along with the value itself.

As you can see, this method returns an array containing the country's official name, native name (in it's native language), 2 letter country code, 3 letter country code, and United Nations numeric code. This will be the case regardless if the source is the hard coded class data or from an HTTP request to the REST Countries API. The following would return the exact same output (note the use of the third optional parameter):

CountryCodes::get($countryCodeType, $countryName, TRUE)

NOTE: Acknowledged country names are exactly as in the REST Countries API. Most are straight forward as with "Haiti" in the example above. However, some aren't so obvious, such as "Venezuela (Bolivarian Republic of)" rather than just "Venezuela"!

The class can be used as a reverse lookup if you happened to have a country code and wish to receive a country name (or other data point from the class). The below example would return the exact same output as the one above:

Retrieving All Countries

There may be instances where you want to retrieve all country codes. The below example will return a multidimensional array of country codes with the same keys as in the example above.

CONTRIBUTING

  1. Fork Repository
  2. Create a descriptive branch name
  3. Make edits to your branch
  4. Squash (rebase) your commits
  5. Create a pull request

LICENSE

This project is licensed under the MIT License - see the LICENSE.md file for details.


All versions of country-codes with dependencies

PHP Build Version
Package Version
Requires php Version >=7.0.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package jabarihunt/country-codes contains the following files

Loading the files please wait ....