PLATFORM
  • Tails

    Create websites with TailwindCSS

  • Blocks

    Design blocks for your website

  • Wave

    Start building the next great SAAS

  • Pines

    Alpine & Tailwind UI Library

  • Auth

    Plug'n Play Authentication for Laravel

  • Designer comingsoon

    Create website designs with AI

  • DevBlog comingsoon

    Blog platform for developers

  • Static

    Build a simple static website

  • SaaS Adventure

    21-day program to build a SAAS

Written By
Views

PHP Detect if non-english

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:

is_english('hello');

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

is_english('NON-ENGLISH-CHAR');

You will most likely receive a false value.

Comments (0)

loading comments