harden code
This commit is contained in:
30
src/Service/FormatText.php
Normal file
30
src/Service/FormatText.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?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, '-');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user