mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-17 14:57:23 +08:00
enhance Inflector helper with ascii function
This commit is contained in:
@@ -475,4 +475,19 @@ class Inflector
|
||||
default: return $number . 'th';
|
||||
}
|
||||
}
|
||||
|
||||
/**+
|
||||
* Converts all special characters to the closest ascii character equivalent.
|
||||
* @param string $string the string to be converted.
|
||||
* @param array $replace the characters to be replaced by spaces.
|
||||
* @return string the translated
|
||||
*/
|
||||
public static function ascii($string, $replace = array())
|
||||
{
|
||||
if (!empty($replace)) {
|
||||
$string = str_replace((array)$replace, ' ', $string);
|
||||
}
|
||||
$string = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
|
||||
return preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $string);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user