vasildakov/postcode
Composer 安装命令:
composer require vasildakov/postcode
包简介
UK Postcode ValueObject
README 文档
README
Synopsis
Value Object that represents an UK postcode
Installation
Here is a minimal example of a composer.json file that just defines a dependency on Postcode:
{
"require": {
"vasildakov/postcode": "^1.1"
}
}
Code Example
Creating a Postcode object
use VasilDakov\Postcode\Postcode; // Create a Postcode $postcode = new Postcode('EC1V 9LB'); // Validate Postcode value print $postcode->valid();
Perform simple validations, parsing and normalisation
$postcode->normalise() // => "EC1V 9LB" $postcode->outcode() // => "EC1V" $postcode->incode() // => "9LB" $postcode->area() // => "EC" $postcode->district() // => "EC1" $postcode->subdistrict() // => "EC1V" $postcode->sector() // => "EC1V 9" $postcode->unit() // => "LB"
Method Overview
| Postcode | outcode() | incode() | area() | district() | subdistrict() | sector() | unit() |
|---|---|---|---|---|---|---|---|
| AA9A 9AA | AA9A | 9AA | AA | AA9 | AA9A | AA9A 9 | AA |
| A9A 9AA | A9A | 9AA | A | A9 | A9A | A9A 9 | AA |
| A9 9AA | A9 | 9AA | A | A9 | null | A9 9 | AA |
| A99 9AA | A99 | 9AA | A | A99 | null | A99 9 | AA |
| AA9 9AA | AA9 | 9AA | AA | AA9 | null | AA9 9 | AA |
| AA99 9AA | AA99 | 9AA | AA | AA99 | null | AA99 9 | AA |
Definitions
Outcode
The outward code is the part of the postcode before the single space in the middle. It is between two and four characters long. A few outward codes are non-geographic, not divulging where mail is to be sent. Examples of outward codes include "L1", "W1A", "RH1", "RH10" or "SE1P".
Incode
The inward part is the part of the postcode after the single space in the middle. It is three characters long. The inward code assists in the delivery of post within a postal district. Examples of inward codes include "0NY", "7GZ", "7HF", or "8JQ".
Area
The postcode area is part of the outward code. The postcode area is between one and two characters long and is all letters. Examples of postcode areas include "L" for Liverpool, "RH" for Redhill and "EH" Edinburgh. A postal area may cover a wide area, for example "RH" covers north Sussex, (which has little to do with Redhill historically apart from the railway links), and "BT" (Belfast) covers the whole of Northern Ireland.
District
The district code is part of the outward code. It is between two and four characters long. It does not include the trailing letter found in some outcodes. Examples of district codes include "L1", "W1", "RH1", "RH10" or "SE1".
Sub-District
The sub-district code is part of the outward code. It is often not present, only existing in particularly high density London districts. It is between three and four characters long. It does include the trailing letter omitted from the district. Examples of sub-district codes include "W1A", "EC1A", "NW1W", "E1W" or "SE1P".
Sector
The postcode sector is made up of the postcode district, the single space, and the first character of the inward code. It is between four and six characters long (including the single space). Examples of postcode sectors include "SW1W 0", "PO16 7", "GU16 7", or "L1 8", "CV1 4".
Unit
The postcode unit is two characters added to the end of the postcode sector. Each postcode unit generally represents a street, part of a street, a single address, a group of properties, a single property, a sub-section of the property, an individual organisation or (for instance Driver and Vehicle Licensing Agency) a subsection of the organisation. The level of discrimination is often based on the amount of mail received by the premises or business. Examples of postcode units include "NY" (from "SW1W 0NY"), "GZ" (from "PO16 7GZ"), "HF" (from "GU16 7HF"), or "JQ" (from "L1 8JQ").
Sources:
- https://en.wikipedia.org/wiki/Postcodes_in_the_United_Kingdom#Formatting
- https://en.wikipedia.org/wiki/London_postal_district#Numbered_divisions
Note on Postcode Validation
Postcodes cannot be validated just with a regular expression. Proper postcode validation requires having a full list of postcodes to check against. Relying on a regex will produce false postives/negatives.
A complete list of Postcodes can be obtained from the ONS Postcode Directory, which is updated every 3 months.
License
Code released under the MIT license
vasildakov/postcode 适用场景与选型建议
vasildakov/postcode 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 341.91k 次下载、GitHub Stars 达 3, 最近一次更新时间为 2016 年 03 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「post」 「postcode」 「uk」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 vasildakov/postcode 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 vasildakov/postcode 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 vasildakov/postcode 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Symfony bundle that integrates the PostNord PHP SDK
Spikkl API client library for PHP
Symfony Bundle for commonground balance functionality
Validates Zip/Postal Codes for any country and provides each country's localized name for their version of the Zip/Postal code (CEP, PLZ, PIN code, Eircode, NPA, CAP, ZIP code, etc.).
Edit Posts button always visible
Extends basic Wordpress features.
统计信息
- 总下载量: 341.91k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 25
- 依赖项目数: 1
- 推荐数: 2
其他信息
- 授权协议: MIT
- 更新时间: 2016-03-11