If is somewhere in the string a non-UTF8 character, preg_match with the modifier u returns false for an error. For example:
<?php
$string = "ABCD\xc3";
$r = preg_match('/^./u',$string, $match);
var_dump($r); //bool(false)
This example for try yourself: https://3v4l.org/qkHl4
The regular expression finds the first character if the non-UTF8 character is removed at the end.
$string = "ABCD";
$r = preg_match('/^./u',$string, $match);
var_dump($r, $match);
//int(1) array(1) { [0]=> string(1) "A" }
Is there an easy way to use regular expressions to identify a UTF-8 character at the beginning for strings that also contain non-UTF8 characters?