mirror of
https://github.com/standardebooks/web.git
synced 2025-07-14 18:42:00 -04:00
Remove flaky iconv and replace with PHP-intl
This commit is contained in:
parent
ba53958596
commit
b812485d8a
3 changed files with 15 additions and 9 deletions
|
@ -1,12 +1,19 @@
|
|||
<?
|
||||
class Formatter{
|
||||
public static function MakeUrlSafe(string $text): string{
|
||||
// Remove apostrophes
|
||||
// We have to do this first so iconv doesn't choke
|
||||
$text = str_replace(['\'', '‘,', '’'], '', $text);
|
||||
public static function RemoveDiacritics(string $text): string{
|
||||
if(!isset($GLOBALS['transliterator'])){
|
||||
$GLOBALS['transliterator'] = Transliterator::createFromRules(':: Any-Latin; :: Latin-ASCII; :: NFD; :: [:Nonspacing Mark:] Remove; :: Lower(); :: NFC;', Transliterator::FORWARD);
|
||||
}
|
||||
|
||||
return $GLOBALS['transliterator']->transliterate($text);
|
||||
}
|
||||
|
||||
public static function MakeUrlSafe(string $text): string{
|
||||
// Remove accent characters
|
||||
$text = iconv('UTF-8', 'ASCII//TRANSLIT', $text) ?: '';
|
||||
$text = self::RemoveDiacritics($text);
|
||||
|
||||
// Remove apostrophes
|
||||
$text = str_replace('\'', '', $text);
|
||||
|
||||
// Trim and convert to lowercase
|
||||
$text = mb_strtolower(trim($text));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue