coercive/slugify

Coercive Slugify 工具

1.2.5 2023-06-15 12:17 UTC

This package is auto-updated.

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


README

Slugify 允许您清理字符串中的字符,例如用于URL重写。其他选项可以检测专有名词,清理空格,将文本转换为utf8等...

获取

composer require coercive/slugify

使用方法

URL

use Coercive\Utility\Slugify;

$sTitleArticle = 'My title is not made to work with a URL rewriting directly, it must be processed before.';
$sSlug = (new Slugify)->clean($sTitleArticle);

# GIVE : my-title-is-not-made-to-work-with-a-url-rewriting-directly-it-must-be-processed-before

概要

use Coercive\Utility\Slugify;

$sText = 'Long text ... Very Long Text ...';
$sSummary = (new Slugify)->substrText($sText);

# GIVE : 300chars text

$sSummary = (new Slugify)->substrText($sText, 500);

# GIVE : 500chars text

名称

use Coercive\Utility\Slugify;

$sName = 'Mary Antoinette';
$bIsName = (new Slugify)->pregName($sName);

# True

$sName = '@Not A valid name !';
$bIsName = (new Slugify)->pregName($sName);

# False

转换为UTF8

use Coercive\Utility\Slugify;

$sString = '!W~"·øΥψ';
$sUtf8String = (new Slugify)->toUTF8($sString);