将字符串转换为缩略语
1.1.0
2019-02-24 21:00 UTC
Requires
- php: >=5.6.0
Requires (Dev)
- phpunit/phpunit: ^7.5
This package is auto-updated.
Last update: 2024-09-25 10:12:28 UTC
README
轻松将字符串转换为缩略语。
1. 使用Composer安装包
composer require oukhennicheabdelkrim/slug
2. 使用方法
2.1. 简单使用
<?php include 'vendor/autoload.php'; use oukhennicheabdelkrim\slug\Slug; $title = 'my title'; $titleId = 3; $mySlug = Slug::getSlug($title); // my-title $mySlug = Slug::getSlug($title,$titleId); // my-title-3
2.2. 配置
配置被设计为尽可能灵活,您可以在配置类 oukhennicheabdelkrim\slug\Conf
中更改分隔符和ID的位置。
2.2.1. 配置示例
class Conf { /** * string Delimiter */ const DELIMITER = '.'; /** * string position of id (right or left) */ const ID_POSITION = 'left'; }
<?php include 'vendor/autoload.php'; use oukhennicheabdelkrim\slug\Slug; $title = 'my title'; $titleId = 3; $mySlug = Slug::getSlug($title); // my.title $mySlug = Slug::getSlug($title,$titleId); // 3.my.title