malenki/slug 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

malenki/slug

最新稳定版本:1.0.0

Composer 安装命令:

composer require malenki/slug

包简介

Simple class to create slug.

README 文档

README

Slug creator, with history and language transliteration.

How to install it

You can clone this repository or use composer:

{
    "require": {
        "malenki/slug": "dev-master",
    }
}

Requirements

You must have Intl PHP extension and mbstring PHP extension.

How to use it

Basic usage

Very simple:

use \Malenki\Slug;

$s = new Slug('Some string!');

echo $s->render();
//or
echo $s; // toString available, give "some-string"

Add custom rules

You can add your own rules to replace some chars:

use \Malenki\Slug;

$s = new Slug('One example string, again!');

$s->rule('!', '-wouah');

echo $s; // "one-example-string-again-wouah"

You can define void slug object to use many string later, usefull if you define rules, to use them again and again:

use \Malenki\Slug;

$s = new Slug();

$s->rule('!', '-wouah')->rule('?', '-huh');
$s->v('Genius!');
echo $s; // "genius-wouah"
$s->v('Genius?');
echo $s; // "genius-huh"

History

By default, Slug use history into running script context, if a generated slug is already present, then add number with increment to it:

use \Malenki\Slug;

$s = new Slug('one-string');
echo $s; // "one-string"
$s = new Slug('one-string');
echo $s; // "one-string-2"
$s = new Slug('one-string');
echo $s; // "one-string-3"

But you can disable this behaviour:

use \Malenki\Slug;

$s = new Slug('one-string');
echo $s->noHistory(); // "one-string"
$s = new Slug('one-string');
echo $s->noHistory(); // "one-string"
$s = new Slug('one-string');
echo $s->noHistory(); // "one-string"

// or

$s = new Slug();
echo $s->noHistory()->v('one-string'); // "one-string"
echo $s->noHistory()->v('one-string'); // "one-string"
echo $s->noHistory()->v('one-string'); // "one-string"

You can use predefined history of slug too, usefull if you have a lot of them in DB for example:

$s = new Slug();
Slug::history(array('one-string', 'another-one'));
echo $s->v('one-string'); // "one-string-2"

Non-ASCII characters

Use other language than english is possible too:

// some french
$s = new Slug('C’est rigolo d’écrire en français !');
echo $s; // "c-est-rigolo-d-ecrire-en-francais"

// some greek
$s = new Slug('Τα ελληνικά σου είναι καλύτερα απο τα Γαλλικά μου!');
echo $s; // "ta-ellenika-sou-einai-kalytera-apo-ta-gallika-mou"

So, enjoy!

统计信息

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

GitHub 信息

  • Stars: 1
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2014-03-25

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固