CodShot
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.

Snippet actions

CodShot user
CodShot user
Updated: 2026-06-03 14:05
Public snippets
0
Forks
CodShot AI Help
Ask about CodShot features, plans, workspace, AI limits, referrals, and public help topics.
Hi! I can help you understand how CodShot works. What would you like to know?
For account-specific or sensitive issues, please open a support ticket. Open support