enricodias/nameize
Composer 安装命令:
composer require enricodias/nameize
包简介
A simple class to correctly capitalize full names.
README 文档
README
A simple class to correctly capitalize full names.
Installation
Require this package with Composer in the root directory of your project
composer require enricodias/nameize
and include the composer's autoloader in your code
include 'vendor/autoload.php';
Usage
Simple usage
echo \enricodias\Nameize::create()->name("Carlo D'ippoliti"); // Carlo D'Ippoliti
or
$nameize = new \enricodias\Nameize(); echo $nameize->name("Matteo Dell'aqcua"); // Matteo Dell'Aqcua echo $nameize->name("john o'grady-smith"); // John O'Grady-Smith
Specifying special characters
The method setAllowedCharacters() receives an array of special characters. Those characters signalizes that the next letter should be in upper case. If no character is specified, the default array("'", '-') is used. If you pass a string, it will be consider a single character.
$nameize = new \enricodias\Nameize(); $nameize->setAllowedCharacters("'"); echo $nameize->name("Matteo Dell'aqcua"); // Matteo Dell'Aqcua echo $nameize->name("john o'grady-smith"); // John O'Grady-smith
or with method chaining:
echo \enricodias\Nameize::create() ->setAllowedCharacters("-") ->name("john o'grady-smith"); // John O'grady-Smith
Minimum length
Some languages require capitalization on the first letter of every word regardless of their size. The setMinLength() method sets the minimum length of which words will be capitalized (min: 1, max: 5, default: 4).
$nameize = new \enricodias\Nameize(); $nameize->setMinLength(1); echo $nameize->name("Tri vu phu"); // Tri Vu Phu echo $nameize->name("Shuanping dai"); // Shuanping Dai
or with method chaining:
echo \enricodias\Nameize::create() ->setMinLength(1) ->name("Tri vu phu"); // Tri Vu Phu
Your application may detect the user's country and use the appropriate minLength value.
Additional features
If you need more features I recommend using a name parser such as https://github.com/theiconic/name-parser
统计信息
- 总下载量: 286
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-08