ashleydawson / slugify
轻量级 slugify 库
1.0.1
2015-05-06 09:19 UTC
Requires
- php: >=5.3.3
Requires (Dev)
- phpunit/phpunit: 4.3.*
This package is auto-updated.
Last update: 2024-09-14 03:06:16 UTC
README
安装
您可以通过 Composer 安装 Slugify。只需在您的 composer.json 文件中添加包,如下所示
{ "require": { "ashleydawson/slugify": "~1.0" } }
然后运行 composer update 以安装该包。
基本用法
使用 slugify 很简单 - 只需实例化 slugifier 服务类并调用 slugify 方法
require_once __DIR__ . '/vendor/autoload.php'; use AshleyDawson\Slugify\Slugifier; $slugifier = new Slugifier(); $text = $slugifier->slugify('Hello World'); // The value of $text will be "hello-world" echo $text;
如果您想更改使用的分隔符,只需将其作为 slugify 方法的第二个参数传递
require_once __DIR__ . '/vendor/autoload.php'; use AshleyDawson\Slugify\Slugifier; $slugifier = new Slugifier(); $text = $slugifier->slugify('Hello World', '_'); // The value of $text will be "hello_world" echo $text;