定制 nazariitsubera/country-aliases 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nazariitsubera/country-aliases

最新稳定版本:v1.0.0

Composer 安装命令:

composer require nazariitsubera/country-aliases

包简介

ISO 3166-1 alpha-2 lookup for thousands of dirty country spellings, plus a PHP helper.

README 文档

README

This bundle packages the country alias lookup generated from the GeoNames datasets plus a thin PHP wrapper you can ship as a Composer package.

Structure

  • data/country_aliases.json – Map {normalized_name: "ISO2"} for every unambiguous alias.
  • data/country_aliases.csv – Two-column CSV (normalized_name,iso2) mirroring the JSON.
  • data/country_aliases_ambiguous.json – Optional file with aliases that match more than one ISO2 code so you can handle them manually.
  • src/ – PHP wrapper exposing a simple runtime API.

Regenerate the data by rerunning the build_country_aliases.py script you used earlier (or fetch the latest GeoNames exports, then rebuild using the same normalization logic). The script should still trim, uppercase, strip accents, and ignore alternate names that look like URLs (strings starting with HTTP/HTTPS) so the output only contains actual country spellings. Once regenerated, drop the new files back into data/.

The JSON file is best suited for programmatic use (load once, look up millions of rows in-memory); the CSV is easier to scan manually.

PHP wrapper

The CountryAliasResolver class in src/ loads data/country_aliases.json and exposes a lookup($value) method that returns the ISO2 code (or null when no match exists). Example:

use CountryAliases\CountryAliasResolver;

$resolver = new CountryAliasResolver(__DIR__ . '/data/country_aliases.json');

var_dump($resolver->lookup('United States of America')); // "US"
var_dump($resolver->lookup('   republic   of   ireland  ')); // "IE"

Drop this repository into a Composer package (e.g., country-aliases/country-aliases), configure PSR-4 autoloading for src/, and you can normalize millions of dirty country strings with a single method call.

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 2
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-21