Slug¶
Castor provides a slug() function to slugify strings for use in URLs or filenames.
It uses the AsciiSlugger from Symfony's String component
and provides the same signature:
use Castor\Attribute\AsTask;
use function Castor\io;
use function Castor\slug;
#[AsTask(description: 'Slugify strings')]
function slugify(): void
{
io()->writeln(slug('Hello World! This is Castor.'));
io()->writeln(slug('Hello World! This is Castor.', separator: '_'));
io()->writeln(slug('좋은 아침이에요', locale: 'en'));
io()->writeln(slug('좋은 아침이에요', locale: 'ko'));
}
Note
The binary version of Castor does not include the intl extension. As a result,
the slug() function in that version may not handle certain special characters.