roksta/punctuator

为文本提供非常简单的标点。

v1.1 2017-05-04 10:58 UTC

This package is auto-updated.

Last update: 2024-09-14 21:16:04 UTC


README

这是一个简单的文本标点器。在标点符号后添加空格并格式化文本。

工作原理

它只是一个简单的脚本,接受一个字符串并检查它,以便:文本以大写字母开头。在每一个句号(.)或问号(?)之后有一个空格,下一个单词以大写字母开头。在每一个逗号(,)之后有一个空格。

特别适用于在将用户输入保存到数据库之前格式化用户输入。它通过Spacer.php特性利用Laravel的模型监听器。

用法

use Roksta\Punctuator\Spacer;

class MyModel extends Model
{
    use Spacer;
    /**
    * set the columns you wish to punctuate in an array in the form shown below;
    * short defines columns where each word is to begin with an uppercase letter, eg, names, locations, etc
    * long is for sentences where spaces will be added after every comma, fullstop, etc.
    */
    public function setPunctuateColumns(): Array
    {
        return ['short' => ['name'], 'long' => ['description', 'comments']];
    }
    
    // Other model functions
}

结果

sam roksta = Sam Roksta

this is very simple.really,really simple = This is very simple. Really, really simple.