Oihana PHP

slugify.php

Table of Contents

Functions

slugify()  : string
Converts a string into a URL-friendly slug.

Functions

slugify()

Converts a string into a URL-friendly slug.

slugify(string $source[, string $separator = '-' ]) : string

The transformation transliterates accented Latin characters to ASCII (via latinize()), lower-cases the result, replaces every run of characters that are not a-z or 0-9 with $separator, and trims leading/trailing separators.

Parameters
$source : string

The input string.

$separator : string = '-'

The separator inserted between words. Default -.

Tags
example
use function oihana\core\strings\slugify;

echo slugify( 'Héllo, World!' )            ; // "hello-world"
echo slugify( '  Café Münsterländer  ' )   ; // "cafe-munsterlander"
echo slugify( 'Foo_Bar Baz' , '_' )        ; // "foo_bar_baz"
author

Marc Alcaraz (ekameleon)

since
1.0.9
Return values
string

The slugified string (lower-case ASCII, words joined by $separator).

On this page

Search results