mlocati/idna
Composer 安装命令:
composer require mlocati/idna
包简介
Library for International Domain Names (IDNA) 2008
关键字:
README 文档
README
International Domain Names PHP library
Introduction & terminology
Historically, we've been able to use domain names composed only by ASCII characters (for instance: www.example.com).
A new technique, called Internationalized Domain Names (IDN for short), allows you to use most of the Unicode characters, so that you can have for instance www.例.中国.
To grant compatibility with all the existing software that makes internet work, domain names containing non-ASCII characters are represented in Punycode, a special format that uses ASCII-only characters.
Mapping
The generation of Punycode starting from an IDN should be case insensitive: browsing to www.example.com should be the same as browsing to www.Example.COM.
In PHP, converting strings to lower case is as easy as calling strtolower, but this function does not work with characters outside the ASCII characters (in fact, it may mess up the IDN names).
If you have the mbstring PHP extension, you may think to use the mb_strtolower PHP function it offers.
By the way, even mb_strtolower isn't a good choice, for these reasons:
- the
mbstringPHP extension may not be available - the
mb_strtolowerbehaviour changes across different PHP versions (for instance,Ԩis correctly converted toԩfor PHP 7.0, but prior versions keptԨ) mb_strtolowerdoes not translate a lot of Unicode characters that are suggested by the standards
Unicode offers a mapping table with the recommended mapping (for instance, case normalization like A to a, but also 。 to .).
Deviation
There are two standards that define the mapping that should be applied to IDN, IDNA2003 and IDNA2008. IDNA2008 is backward compatible with IDNA2003, but there are some incompatible differences.
For instance, IDNA2003 required that ß mapped to ss, whereas IDNA2008 allows the usage of ß. So, older browsers and client softwares resolved www.schloß.com to the Punycode corresponding to www.schloss.com, whereas newer browsers resolve it to the Punycode of www.schloß.com.
Since the resulting Punycode is different (it's called deviation), this lead to big security issues, and you need to know that a domain name is deviated.
Advantages of this library
- no dependencies from any PHP extension
- not dependent from any other PHP library
- consistency across different PHP versions
- results are granted to follow the standards (it's not just a bare multibyte to punycode conversion library)
- designed with speed in mind
- compatible with any PHP version ranging from PHP 5.3 to the most recent PHP versions (8.2 at the time of writing this)
Sample usage
require_once 'autoload.php'; // Not required if you use composer $domain = \MLocati\IDNA\DomainName::fromName('www。schloß.COM'); echo "Name: ", $domain->getName(), "\n"; echo "Punycode: ", $domain->getPunycode(), "\n"; echo "Deviated: ", $domain->isDeviated() ? 'yes' : 'no', "\n"; echo "Deviated Name: ", $domain->getDeviatedName(), "\n"; echo "Deviated Punycode: ", $domain->getDeviatedPunycode(), "\n";
output:
Name: www.schloß.com
Punycode: www.xn--schlo-pqa.com
Deviated: yes
Deviated Name: www.schloss.com
Deviated Punycode: www.schloss.com
Do you really want to say thank you?
You can offer me a monthly coffee or a one-time coffee 😉
mlocati/idna 适用场景与选型建议
mlocati/idna 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 976.97k 次下载、GitHub Stars 达 9, 最近一次更新时间为 2016 年 11 月 03 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「i18n」 「idna」 「l10n」 「ascii」 「domain」 「name」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 mlocati/idna 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mlocati/idna 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 mlocati/idna 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A library for encoding and decoding internationalized domain names
A library for encoding and decoding internationalized domain names
An implementation of UTS#46 Unicode IDNA Compatibility Processing.
idna-convert library based on http://idnaconv.phlymail.de/
Easy to use i18n translation PHP class for multi-language websites
A library for encoding and decoding internationalized domain names
统计信息
- 总下载量: 976.97k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 9
- 点击次数: 36
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-11-03