Files
MtoRagSystem/src/Service/FormatText.php
2026-02-15 16:01:08 +01:00

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, '-');
}
}