Published

Laravel 5.5 String Helper Function: ascii

The signature of the ascii method is. LanguageLanguage ParameterBulgarian bg German de

The ascii helper method accepts only one argument: $value. $value should always be a string, or something that can be cast into a string. The function converts a string in the UTF-8 encoding into its ASCII equivalent.

This method is useful when communicating with other software platforms that require ASCII, or when complying with protocols (such as HTTP) about how headers, or some values, need to be formatted.

Signature

The signature of the ascii method is:

1public static function ascii(
2 $value,
3 $language = 'en' // Also accepts `bg` or `de`
4 );

Example Use

The ascii method accepts a $language parameter (which defaults to en) that can be used:

1use Illuminate\Support\Str;
2 
3// Outputs "sht"
4echo Str::ascii('щ', 'bg');

The ascii method provides support for the following additional languages out of the box:

Language Language Parameter
Bulgarian bg
German de

In Laravel 5.5, the additional language features provided by the Laravel framework have been adapted from the danielstjules/stringy library.

G> Appendix D: Appendix D: Language Specific Replacements contains reference tables for each of the supported language-specific replacements.

1use Illuminate\Support\Str;
2 
3// The following will output "a test string"
4// in the ASCII encoding.
5 
6echo Str::ascii('a test string');

Recent articles

Stillat

Covering topics from JavaScript to Laravel, and everything in-between since 2012.

Resources

© Stillat, LLC. All right reserved.
Code highlighting provided by Torchlight