How To Find Non ASCII Characters In a String In Laravel?

Finding Non ASCII characters in Laravel would have been a big problem, had it not been for the support of Laravel library that has given us ease to locate them easily with examples. See the tutorial below to find it how you can locate Non ASCII characters in Laravel.

String: string does not have any non Ascii character.

isAscii output: true

String: string have one Non ASCII characters

isAscii output: false

We are using Ascii() function to find the non ASCII characters. Lets see below how it goes with the code.


namespace App\Http\Controllers;

use Illuminate\Support\Str;

class HomeController extends Controller {
	 * Show the application dashboard.
	 * @return \Illuminate\Contracts\Support\Renderable
	public function index() {
		$str     = 'string have one Ńon ASCII characters';
		$isAscii = Str::isAscii( $str );
		if ( $isAscii ) {
			echo "string has all Ascii characters";
		} else {
			echo "string has one or more non Ascii characters";

Please check Laravel 8.0 docs for a detailed version. Let us know if you face any problem in the comments below. We will address it.