3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function slug($title, $separator = '-') { // Remove all characters that are not the separator, letters, numbers, or whitespace. $title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', mb_strtolower($title)); // Convert all dashes/undescores into separator $flip = $separator == '-' ? '_' : '-'; $title = preg_replace('!['.preg_quote($flip).']+!u', $separator, $title); // Replace all separator characters and whitespace by a single separator $title = preg_replace('!['.preg_quote($separator).'\s]+!u', $separator, $title); return trim($title, $separator); } slug('https://eu.api.battle.net/wow/battlePet/ability/640');
Output for 4.4.0 - 4.4.9, 5.0.5 - 7.1.0
Output for 4.3.11, 5.0.0 - 5.0.4
Warning: preg_replace(): Compilation failed: PCRE does not support \L, \l, \N, \P, \p, \U, \u, or \X at offset 4 in /in/HYJhX on line 5
Output for 4.3.0 - 4.3.10
Warning: Compilation failed: PCRE does not support \L, \l, \N, \P, \p, \U, \u, or \X at offset 4 in /in/HYJhX on line 5