added Str::ascii method and fixed accented character problem in URL::slug.
This commit is contained in:
@@ -57,6 +57,21 @@ class Str {
|
||||
return function_exists('mb_strlen') ? mb_strlen($value, Config::get('application.encoding')) : strlen($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert a string to 7-bit ASCII.
|
||||
*
|
||||
* @param string $value
|
||||
* @return string
|
||||
*/
|
||||
public static function ascii($value)
|
||||
{
|
||||
$foreign = Config::get('ascii');
|
||||
|
||||
$value = preg_replace(array_keys($foreign), array_values($foreign), $value);
|
||||
|
||||
return preg_replace('/[^\x09\x0A\x0D\x20-\x7E]/', '', $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a random alpha or alpha-numeric string.
|
||||
*
|
||||
|
||||
@@ -109,6 +109,8 @@ class URL {
|
||||
*/
|
||||
public static function slug($title, $separator = '-')
|
||||
{
|
||||
$title = html_entity_decode(Str::ascii($title), ENT_QUOTES, Config::get('application.encoding'));
|
||||
|
||||
// Remove all characters that are not the separator, letters, numbers, or whitespace.
|
||||
$title = preg_replace('![^'.preg_quote($separator).'\pL\pN\s]+!u', '', Str::lower($title));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user