public static function friendly_title($str, $sep = '-', $lowercase = false)
{
// Allow underscore, otherwise default to dash
$sep = $sep != '_' ? '-' : $sep;
// Decode all entities to their simpler forms
$str = html_entity_decode($str, ENT_QUOTES, 'UTF-8');
$trans = array(
'\s+' => $sep, // one or more spaces => seperator
$sep.'+' => $sep, // multiple seperators => 1 seperator
$sep.'$' => '', // ending seperator => (nothing)
'^'.$sep => '', // starting seperator => (nothing)
'\.+$' => '', // ending dot => (nothing)
'\?' => '' // question mark
);
foreach ($trans as $key => $val)
{
$str = preg_replace("#".$key."#i", $val, $str);
}
// Only allow 7bit characters
$str = static::ascii($str);
// only allow chars and numbers
$str = preg_replace("#[^a-z0-9\-\._]#i", '', $str);
$str = \Security::strip_tags($str);
if ($lowercase === true)
{
$str = \Str::lower($str);
}
return $str;
}
It looks like you're new here. If you want to get involved, click one of these buttons!