30 lines
685 B
PHP
30 lines
685 B
PHP
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
class FormatText
|
|
{
|
|
function slugify(string $text): string
|
|
{
|
|
$text = mb_strtolower($text, 'UTF-8');
|
|
|
|
// Umlaute ersetzen
|
|
$replacements = [
|
|
'ä' => 'ae',
|
|
'ö' => 'oe',
|
|
'ü' => 'ue',
|
|
'ß' => 'ss'
|
|
];
|
|
$text = str_replace(array_keys($replacements), $replacements, $text);
|
|
|
|
// Nicht erlaubte Zeichen entfernen
|
|
$text = preg_replace('/[^a-z0-9\s.-]/', '', $text);
|
|
|
|
// Leerzeichen zu Bindestrichen
|
|
$text = preg_replace('/[\s-]+/', '-', $text);
|
|
|
|
$text = preg_replace('/\./', '-', $text);
|
|
|
|
return trim($text, '-');
|
|
}
|
|
} |