blazorazem/sanitizer

Sanitizer 是一个方便用于清洗姓名、电子邮件地址、URL 等的包。

1.2.1 2015-05-09 00:31 UTC

This package is auto-updated.

Last update: 2024-09-15 00:09:18 UTC


README

Sanitizer 是一个方便用于清洗姓名(人名、地名或某些特殊事物)、电子邮件地址、URL 等的包。

通用功能

  • 将姓名(人名、地名或某些特殊事物)转换为清洗过的 CamelCase 格式
  • 将电子邮件地址转换为清洗过的小写电子邮件格式
  • 将字符字符串转换为清洗过的 URL 格式

URL 清洗功能

  • 将内部字符编码转换为 UTF-8
  • 替换货币符号
  • 用无重音字符替换带重音字符
  • 用拉丁字符替换西里尔字符
  • 替换其他保留、不安全和特殊字符
  • 转换为小写,去除空格并返回清洗过的 URL 字符串

通过 Composer 安装

Sanitizer 可以通过 Composer 以 blazorazem/sanitizer 的方式安装。

首先包含 Sanitizer 包。

"blazorazem/sanitizer": "dev-master"

现在只需使用 Sanitizer 类。

use BlazOrazem\Sanitizer;

独立使用

下载一个版本或克隆此存储库,然后需要或包含其 src/Sanitizer.php 文件。

基本用法

将姓名(人名、地名或某些特殊事物)转换为 CamelCase 格式。

Sanitizer::name('mr. chuck norris');
// Returns: Mr. Chuck Norris

验证和清洗电子邮件地址格式。

Sanitizer::email('CHUCK@norris.COM');
// Returns: chuck@norris.com

Sanitizer::email('CHUCK @norris?.COM');
// Returns: null

Sanitizer::email('CHUCK @norris?.COM');
// Returns: null

清洗 URL

Sanitizer::url('this Shőüld be \n sąn`itiz˘ed /// web-safe STRING/ with € cú˘rrenc~y at THE...END');
// Returns: this-should-be-sanitized-web-safe-string/-with-eur-currency-at-the.end

转换带重音字符

Sanitizer::url('Ŵĥăţ ĩş ŷōuř ñąmĕ? Mý ʼnǎmę ĭŝ Ĉħǚçķ Ñöŕŗǐś.');
// Returns: what-is-your-name-my-name-is-chuck-norris

将西里尔字符 URL 转换为拉丁字符

Sanitizer::url('Как вас зовут? Меня зовут Чхучк Норрис.');
// Returns: kak-vas-zovut-mena-zovut-chuck-norris

需求

Sanitizer 包需要 PHP 5.3 或更高版本,并且没有依赖项。

支持

作者

许可证

Sanitizer 在 MIT 许可证下发布。

Copyright (C) 2015 Blaz Orazem

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.