wernerdweight/canonicalizer

Simple PHP string canonicalizer

2.0.1 2023-02-21 16:58 UTC

This package is auto-updated.

Last update: 2024-11-06 16:36:30 UTC


README

Simple PHP string canonicalizer

Build Status Latest Stable Version Total Downloads License

Instalation

  1. Download using composer
composer require wernerdweight/canonicalizer
  1. Use in your project
use WernerDweight\Canonicalizer\Canonicalizer;
 
$string = 'This is an interesteing string with some strange cháračtěřš in it. Хорошо?'
$maxLength = 255;   // maximal resulting canonical length (excessive chars will be trimmed)

$canonicalizer = new Canonicalizer($maxLength);
$canonical = $canonicalizer->canonicalize($string);

echo $canonical;    // this-is-an-interesting-string-with-some-strange-characters-in-it-choroso

API

  • canonicalize(string $string[, string $ending[, string $separator]]): string \

    • $string - string to be canonicalized,
    • $ending - string to be appended at the end of canonicalized string (ending is included in $maxLength) - useful to append ids, file formats etc.; default '' (empty string),
    • $separator - string used to separate canonicalized words; default - (dash).
  • setBeforeCallback(?callable): self
    Allows to set a callback function that will be called before the given string is canonicalized.
    The callback should respenct this definition function (string): string.
    Warning: the callback remains in place until explicitly nulled ($canonicalizer->setBeforeCallback(null)).

  • setAfterCallback(?callebld): self Allows to set a callback function that will be called after the given string is canonicalized. The callback should respenct this definition function (string): string. Warning: the callback remains in place until explicitly nulled ($canonicalizer->setAfterCallback(null)).