Categories
Coding

How to detect English/ASCII string in PHP

There is not direct function for this in my knowledge. But it can be done easily like so.

if ( mb_strlen( $string, 'ASCII' ) === mb_strlen( $string, 'utf-8' ) ) {
    return true;
}

By Abhineet Mittal

Abhineet is IIM Alumnus and Founder of popular Digital Publishing Platform, Sahityapedia. He is a technology enthusiast by hobby & an avid reader.

Leave a Reply

Your email address will not be published. Required fields are marked *