- function_exists: documentation ( source)
- trim: documentation ( source)
- preg_replace: documentation ( source)
- strtolower: documentation ( source)
- setlocale: documentation ( source)
<?php
$text = "duls~ao vafan";
$separator = '_';
$text = preg_replace('/[^\\pL\d]+/u', $separator, $text);
if(function_exists('iconv')){
setlocale(LC_CTYPE, 'fr_FR.UTF-8');
$text = iconv('UTF-8','ASCII//TRANSLIT//IGNORE',$text);
}
$text = strtolower($text);
$text = preg_replace('/[^-\w]+/', $separator, $text);
$text = trim($text, '-_ ');
echo $text;