wernerdweight / canonicalizer
Simple PHP string canonicalizer
Installs: 4 928
Dependents: 0
Suggesters: 0
Security: 0
Stars: 1
Watchers: 1
Forks: 0
Open Issues: 1
pkg:composer/wernerdweight/canonicalizer
Requires
- php: >=8.1
- thecodingmachine/safe: ^2.4
Requires (Dev)
README
Simple PHP string canonicalizer
Instalation
- Download using composer
composer require wernerdweight/canonicalizer
- 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 definitionfunction (string): string.
Warning: the callback remains in place until explicitly nulled ($canonicalizer->setBeforeCallback(null)). -
setAfterCallback(?callebld): selfAllows to set a callback function that will be called after the given string is canonicalized. The callback should respenct this definitionfunction (string): string. Warning: the callback remains in place until explicitly nulled ($canonicalizer->setAfterCallback(null)).