PHP Detect if non-english

Updated Jun 9, 2020・1 minute read Post By Tony Lea

If there ever comes a time when you wish to detect whether a string has english characters or not... There is a very simple way of representing this in PHP. Here is a PHP function which will return true if the string contains english characters or it will return false if there are foreign characters.

function is_english($str)
	if (strlen($str) != strlen(utf8_decode($str))) {
		return false;
	} else {
		return true;

So, if you were to pass the function:


You would receive back a true value. Alternatively if you were to call this function as the following:


You will most likely receive a false value.

© 2020 DevDojo LLC. All rights reserved.