This function is meant to sanitise a given value but instead it outputs "n-a" as if no value was specified. It has to be the simplest issue but right this moment it has me beat.
function slug($text){
// replace non letter or digits by -
$text = preg_replace('~[^pLd]+~u', '-', $text);
// trim
$text = trim($text, '-');
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// lowercase
$text = strtolower($text);
// remove unwanted characters
$text = preg_replace('~[^-w]+~', '', $text);
if (empty($text))
{
return 'n-a';
}
return $text;
}
I'd appreciate some input.
You need to change your first regex which seems to be incorrect, should be,
// replace non letter or digits by -
$text = preg_replace('~[^\w\d]+~u', '-', $text);