/** Takes text and converts it to an ASCII-only string (characters with code between 32 and 127, plus \t, \n and \r).
* @param string $text The text to be converted.
* @param string $locale='' The locale for the string. If not specified we consider the current locale.
* @return string
*/
public function asciify($text, $locale = '')
{
if (!strlen($locale)) {
$locale = \Localization::activeLocale();
}
$language = substr($locale, 0, strcspn($locale, '_'));
$text = \URLify::downcode($text, $language);
if (preg_match('/[^\\t\\r\\n\\x20-\\x7e]/', $text)) {
if (function_exists('iconv')) {
$t = @iconv(APP_CHARSET, 'US-ASCII//IGNORE//TRANSLIT', $text);
if (is_string($t)) {
$text = $t;
}
}
$text = preg_replace('/[^\\t\\r\\n\\x20-\\x7e]/', '', $text);
}
return $text;
}