PHP
Public
Simple Slug Generator
A compact PHP slug generator for URLs and filenames.
#php
#slug
#string
#utility
PHP
<?php
function makeSlug(string $text): string
{
$text = strtolower(trim($text));
$text = preg_replace('/[^a-z0-9]+/i', '-', $text);
$text = trim((string) $text, '-');
return $text !== '' ? $text : 'item';
}
echo makeSlug('Simple PHP Slug Generator!');
Notes
For multilingual text, consider transliteration before slug generation.