定制 treehouselabs/slugifier 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

treehouselabs/slugifier

最新稳定版本:v1.0.1

Composer 安装命令:

composer require treehouselabs/slugifier

包简介

Slugifier

README 文档

README

Simple, extensible library that converts a string to a slug.

Another one?

Yep, sorry. We think this one is pretty good though. Check out the features to see if it's good for you, too.

Features

  • Lightweight: no dependencies, other than the mbstring and iconv extensions, which are almost always present.
  • Easy to use: (new Slugifier())->slugify('Look Ma, no hands!'); // look-ma-no-hands
  • Handles special characters, all kinds of quotes, transliteration, HTML entities, and more. All out of the box.
  • Extensible: add your custom translations
  • PSR-4 compatible and written using PRS-2 coding guidelines Scrutinizer Code Quality
  • Well-tested Build Status

Usage

$slugifier = new Slugifier(); $slugifier->slugify('Look má, I\'m a „slug”'); // look-ma-im-a-slug

Use a different delimiter:

$slugifier = new Slugifier(); $slugifier->slugify('Foo, bar & baz', '_'); // foo_bar_baz

Add special translations:

$slugifier = new Slugifier(); $slugifier->addTranslator(new EnglishTranslator()); $slugifier->slugify('Cow & chicken'); // cow-and-chicken

Or write your own:

class CowTranslator implements TranslatorInterface { public function translate($str) { return str_ireplace('cow', 'supercow', $str); } } $slugifier = new Slugifier(); $slugifier->addTranslator(new CowTranslator()); $slugifier->slugify('Cow to the rescue'); // supercow-to-the-rescue

Changing the default behaviour

By default, special characters, quotes, HTML entities and more are converted. You can disable this behaviour by passing false to the constructor. This way you can start from scratch and add your own translators. The iconv transliteration is still performed though as we want to convert to ascii while preserving as much of the original data as possible.

统计信息

  • 总下载量: 214.28k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 8
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固