PHP Detect if non-english

's avatar
Tony Lea ・June 10, 2011
1 minute read ・Updated July 17, 2020

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.

Still have a question?

Get help or discuss anything development/design related.

Start a discussion